Computer >> Computer tutorials >  >> Programming >> Python

How to match a whitespace in python using Regular Expression?


The following code matches whitespaces in the given string.

Example

import re
result = re.search(r'[\s]', 'The Indian Express')
print result

output

<_sre.SRE_Match object at 0x0000000005106648>

Example

The following code finds all whitespaces in the given string and prints them

import re
result = re.findall(r'[\s]', 'The Indian Express')
print result

output

[' ', ' ']