Python regular expressions OR

前端 未结 2 852
抹茶落季
抹茶落季 2020-11-30 08:34

Suppose I want a regular expression that matches both \"Sent from my iPhone\" and \"Sent from my iPod\". How do I write such an expression?

I tried things like:

相关标签:
2条回答
  • 2020-11-30 09:00
    re.compile("Sent from my (?:iPhone|iPod)")
    

    If you need to capture matches, remove the ?:.

    Fyi, your regex didn't work because you are testing for one character out of i,P,h,o,n,e or one character out of i,P,o,d..

    0 讨论(0)
  • 2020-11-30 09:10
    re.compile("Sent from my (iPhone|iPod)")
    
    0 讨论(0)
提交回复
热议问题