How to match nonword characters in Python using Regular Expression?

PythonServer Side ProgrammingProgramming

This code below matches all non-word characters from the given string and prints their list.

Example

import re
s = 'ab5z8d*$&Y@'
regx = re.compile('\W')
result = regx.findall(s)
print result

Output

This gives the output

['*', '$', '&', '@']
raja
Updated on 18-Feb-2020 07:47:53

Advertisements