Reputation: 33
I'm trying to find a regular expression to match all the combination of chars that have the string "question" but not have or contain the string "ion".
examples:
questionxxxx ------> match
xxxquestion--------> match
questionxxxxion----> not match
xxxquestionxxx-----> match
xxxionxxxquestion--> not match
I'm almost there but is missing me something!!!
this is what I have done:
((?=.*question(?!.*ion.*).).*)|^question$
This expression exclude all the strings with "ion" separated from "quest" but unfortunately also exclude "xxxquestion"
Upvotes: 3
Views: 1124
Reputation: 89557
With perl compatible regex you can use this:
^(?:(question)|[^i]+|i(?!on))+(?(1)|(?!))$
With other regex flavors you can use this:
^(?:[^qi]+|q(?!uestion)|i(?!on))*question(?:[^i]+|i(?!on))*$
Upvotes: 0
Reputation: 4795
I have no idea how general you needed this solution to be, but the following works for your example:
(?!.*(?<!quest)ion)^.*question.*$
Upvotes: 5