Skip to content Skip to sidebar Skip to footer

Fixing Negative Assertion For End Of String

I am trying to accept a capture group only if the pattern matches and there is not a specific word before the end of the group. I've tried a # of approaches and none seem to work,

Solution 1:

I would recommend putting your negative look-ahead at the beginning of your pattern. This first checks if your reject word exists in your string and only if it isn't there does it try to match the rest of the string:

(?!.*Rejected.*)RC:\*.*?(?P<Capture>(Bob|David|Ted|Alice)).*

https://regex101.com/r/iP2xY0/6


Post a Comment for "Fixing Negative Assertion For End Of String"