How to concisely cascade through multiple regex statements in Python

前端 未结 7 838
天涯浪人
天涯浪人 2020-12-08 05:51

My dilemma: I\'m passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there\'s a match in the first regex, do one thing

相关标签:
7条回答
  • 2020-12-08 06:14

    Here your regexs and matches are not repeated twice:

    match = re.match('regex1', string)
    if match:
        # do stuff
        return
    
    match = re.match('regex2', string)
    if match:
        # do stuff
        return
    
    0 讨论(0)
提交回复
热议问题