Python regular expressions OR

前端 未结 2 863
抹茶落季
抹茶落季 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..

提交回复
热议问题