How you can get a true/false from a Python regular expressions?

PythonServer Side ProgrammingProgramming

When you use match and search methods of module re, if there is a match, it has bool value of True and if there is no match, you get None that has a bool value of False.

Match objects are always true, and None is returned if there is no match

>>> bool(re.search("def", "abcdefgh"))
True
>>> bool(re.search("rest", "pqrstuv"))
False
raja
Published on 03-Jan-2018 16:23:54
Advertisements