Link to home
Start Free TrialLog in
Avatar of jyotishb
jyotishb

asked on

Regular expression

Hi,
How do i find out if a string contains any non alpha numeric characters using regular expression, in python?

Thanks

Avatar of RichieHindle
RichieHindle

import re
def has_non_alpha_num(s):
    return bool(re.search(r'[^a-zA-Z0-9]', s))

print has_non_alpha_num("123")  # Prints False
print has_non_alpha_num("abc")  # Prints False
print has_non_alpha_num("Hello!")  # Prints True
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial