Regex match two words and not match other

How can I write a regex to match follow conditions:

( (iphone|ipod) OR ( android AND mobile AND (NOT gt-p) ) )

Would someone help me?

Edit:

With the help in comments I've the follow code:

iphone|ipod|(android(?!.*?gt-p)(?:s*mobile))?

It is the same regex with more on group to android alone not match... is it correct?


This might be what you're after:

iphone|ipod|android(?!.*?gt-p)(?:s*mobile)?

https://regex101.com/r/xT8rD4/1

It will allow android and android mobile not followed by gt-p . If it should only allow android mobile , it's an easy fix.


Here's my offering for you

(^((?!gt-p).)*mobile((?!gt-p).)*android((?!gt-p).)*$)|(^((?!gt-p).)*android((?!gt-p).)*mobile((?!gt-p).)*$)|iphone|ipad

It matches for anything with "ipad" or "iphone" or ("android" and "mobile" in any order, as long it doesn't also contain "gt-p")

https://regex101.com/r/dR5rE4/1

链接地址: http://www.djcxy.com/p/77082.html

上一篇: 正则表达式:匹配多个单词的第一个字母

下一篇: 正则表达式匹配两个单词而不匹配其他单词