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
Updated on 18-Feb-2020 07:49:30

Advertisements