Regex 在正则表达式中具有受控多次发生的一组模式中的模式白名单
我希望以下示例返回匹配Regex 在正则表达式中具有受控多次发生的一组模式中的模式白名单,regex,string,Regex,String,我希望以下示例返回匹配 我喜欢foobar.com 我喜欢google.com和foobar.com 我喜欢foobar.com和google.com 我喜欢foobargoogle.com和谷歌foobar.com 我喜欢yahoo.com和foobar.com 我喜欢foobar.com和yahoo.com 我喜欢foobaryahoo.com和yahoofoobar.com 我不希望以下示例返回匹配 我喜欢雅虎网站 我喜欢foobaryahoo.com 我喜欢google.com 我
- 我喜欢foobar.com
- 我喜欢google.com和foobar.com
- 我喜欢foobar.com和google.com
- 我喜欢foobargoogle.com和谷歌foobar.com
- 我喜欢yahoo.com和foobar.com
- 我喜欢foobar.com和yahoo.com
- 我喜欢foobaryahoo.com和yahoofoobar.com
- 我喜欢雅虎网站
- 我喜欢foobaryahoo.com
- 我喜欢google.com
- 我喜欢foobargoogle.com
- 我喜欢google.com和yahoo.com
- 我喜欢foobargoogle.com和foobaryahoo.com
(?!(^.*((google)|(yahoo))\.com.*$))(^.*\w+\.com.*$)
但一旦“google.com”或“yahoo.com”出现,即使“foobar.com”出现在它之前,它也没有匹配的终止
我喜欢foobar.com,但不喜欢google.com
基本上,我希望它忽略字符串中的“google.com”和“yahoo.com”,并检测任何其他类型:“\w+.com”
注:
- google.com和yahoo.com只是例子。所以,它应该忽略任何字符串长度的字母数字字符的匹配集
- 忽略大小写和空格
突然将(?:google | yahoo)(?:\.com)
或google
字符串与以下可选的yahoo
匹配。请看演示.com
和以下PCRE动词(?:google | yahoo)(?:\.com)(*SKIP)(*F)
将导致上一次匹配失败。下面的(*SKIP)(*F)
或将匹配所有未后跟|
或google
字符串的边界。请看演示yahoo
< > >代码>((:谷歌雅虎)\W)+\COM现在ReGEX引擎将考虑匹配边界作为起点,它突然匹配一个或多个单词字符,但不符合<代码>谷歌< /代码>或<代码>雅虎< /C> > 。
仅帮助匹配以\.com
结尾的字符串.com
- 没必要这么复杂。
这将准确地查找您在“需要”行中突出显示的内容 (?:\w(?)?
(?:google|yahoo)(?:\.com)?(*SKIP)(*F)|(?:(?!google|yahoo)\w)+\.com
^ ^ ^
|------Part you don't want-----------|------------Part you want--|
# (?:\w(?<!google)(?<!yahoo))+\.com
(?:
\w # Match words but not google or yahoo behind
(?<! google )
(?<! yahoo )
)+
\. com