Python regular expressions return true/false

前端 未结 6 1212
情歌与酒
情歌与酒 2020-12-23 02:44

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

<_sre.SRE_Match object at ...>         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 03:16

    Ignacio Vazquez-Abrams is correct. But to elaborate, re.match() will return either None, which evaluates to False, or a match object, which will always be True as he said. Only if you want information about the part(s) that matched your regular expression do you need to check out the contents of the match object.

提交回复
热议问题