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

Updated on: 20-Feb-2020

240 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements