开发者

Regex to select a string not having a certain word followed by a certain set of words

I am trying to find a regex that will return true if a string ends with jaxws.managed but does not contain delegate.

For example:

abc/delegate/xyz/jaxws/managed should return false, while

abc/def/xyz/jaxws/managed should return true

I tried using the regex

([^(delegate)])+([a-z]*开发者_StackOverflow[\\/]jaxws[\\/]managed[\\/])+

but it fails.


Assuming Java regex,

^(?!.*delegate).*jaxws/managed$


You should specify what regex engine you're using.

Nevertheless...

return false if it contains "delegate" anywhere: /delegate/; -> return false

if we don't return, and it ends in "jaxws/managed", return true: /jaxws\/managed$/; -> return true

if you're using Perl, I suggest applying m{} instead of // to avoid the "leaning toothpick syndrome". Refer to perlre for more information.


If you are using Javascript, you can use this regEx:

 **/^((?!(delegate)).)*jaxws\/managed$/**
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜