Python regular expressions return true/false

前端 未结 6 1234
情歌与酒
情歌与酒 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:03

    Here is my method:

    import re
    # Compile
    p = re.compile(r'hi')
    # Match and print
    print bool(p.match("abcdefghijkl"))
    

提交回复
热议问题