Computer >> Computer tutorials >  >> Programming >> Python

How to write Python regular expression to check alphanumeric characters?


In Python there is a special sequence \w for matching alphanumeric and underscore when the LOCALE and UNICODE flags are not specified. 

Example

import re
result = re.search(r'^\w+$', 'Tutorials123')
print result.group()

Output

Tutorials123