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
Published on 29-Dec-2017 12:41:38
Advertisements