Regex -匹配URL中除特定单词之外的任何字符序列

时间:2021-07-20 10:35:37

I want to match a URL that contains any sequence of valid URL characters but not a particular word. The URL in question http://gateway.ovid.com and I want to match anything but the word 'gateway' so:

我希望匹配一个URL,该URL包含任何有效的URL字符序列,但不包含特定的单词。问题中的URL http://gateway.ovid.com和我想匹配除“gateway”这个词之外的任何东西:

but

Something like the following:

像下面这样:

^http://([a-z0-9\-\.]+|(?<!gateway))\.ovid\.com$

but it doesn't seem to work.

但这似乎行不通。


Update: Sorry forget to mention the language, it's C#.NET

更新:抱歉忘了提到语言,它是c#。net

2 个解决方案

#1


12  

Your regex is almost correct except the extra '|' after '+'. Remove the '|'

您的regex几乎是正确的,除了+后面的额外的“|”。删除“|”

^http://([a-z0-9\-\.]+(?<!gateway))\.ovid\.com$

#2


-2  

You didn't specify host language, but why not something like this psuedocode

您没有指定主机语言,但是为什么不指定这个psuedocode

bool good = Regex.Match( yourRegex ) and not Regex.Match(gateway)

#1


12  

Your regex is almost correct except the extra '|' after '+'. Remove the '|'

您的regex几乎是正确的,除了+后面的额外的“|”。删除“|”

^http://([a-z0-9\-\.]+(?<!gateway))\.ovid\.com$

#2


-2  

You didn't specify host language, but why not something like this psuedocode

您没有指定主机语言,但是为什么不指定这个psuedocode

bool good = Regex.Match( yourRegex ) and not Regex.Match(gateway)