How do i match just spaces and newlines with Python regex?


The following matches and prints just spaces and newlines in the given string using Python regex

Example

import re
foo = ' I find
  Tutorialspoint
  useful'
result = re.findall(r'\s+', foo)
print result

Output

This gives the output

[' ', ' ', ' \n ', ' \n ']

Updated on: 19-Feb-2020

406 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements