How to match whitespace but not newlines using Python regular expressions?


The following code matches only the whitespaces but not newlines in the given string

Example

import re
print re.findall(r"(\s){1,}","""I find
    Tutorialspoint useful""")

Output

This gives the output

[' ', ' ', ' ']

Updated on: 19-Feb-2020

599 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements