How to match nonword characters in Python using Regular Expression?nnnn



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

['*', '$', '&', '@']

Advertisements