Fix Python – Python regular expressions return true/false

Question

Asked By – nobody

Using Python regular expressions how can you get a True/False returned? All Python returns is:

<_sre.SRE_Match object at ...>

Now we will see solution for issue: Python regular expressions return true/false


Answer

Match objects are always true, and None is returned if there is no match. Just test for trueness.

if re.match(...):

This question is answered By – Ignacio Vazquez-Abrams

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0