How to match a whitespace in python using Regular Expression?

PythonServer Side ProgrammingProgramming

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

[' ', ' ']
raja
Published on 29-Dec-2017 13:24:23
Advertisements