Sibi JV
Sibi JV

Reputation: 263

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]*[\\/]jaxws[\\/]managed[\\/])+

but it fails.

Upvotes: 0

Views: 152

Answers (3)

Nitesh
Nitesh

Reputation: 1550

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

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

Upvotes: 0

guidj0s
guidj0s

Reputation: 11

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.

Upvotes: 1

kennytm
kennytm

Reputation: 523524

Assuming Java regex,

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

Upvotes: 1

Related Questions