How to match only non-digits in Python using Regular Expression?

PythonServer Side ProgrammingProgramming

The following code matches only non-digits in the given string using python regular expression.

Example

import re
m = re.search(r'\D+', '5Need47for Speed 2')
print m

output

<_sre.SRE_Match object at 0x0000000004FE6648>

The following code finds all non-digits in the given string and prints them as a list

Example

import re
m = re.findall(r'\D+', '5Need47for Speed 2')
print m

output

['Need', 'for Speed ']
raja
Updated on 18-Feb-2020 07:56:50

Advertisements