Home > database >  Join multiple complex regex queries with pipe
Join multiple complex regex queries with pipe

Time:12-15

If I use this regex:

^((?!^aa$).)*$

it works as expected: deselects 'aa' at the line start. But it doesn't if I try to combine it with a similar one:

^((?!^aa$).)*$|^((?!^ss$).)*$

Can anyone explain why, please?

I tried using both regex group kinds, escape slashes the possible ways, google the question a lot, and read many regex docs. But this is too complicated for me yet.

CodePudding user response:

To disallow aa and ss an alternation inside a lookahead can be used at ^ start.

^(?!aa$|ss$).*

See this demo at regex101 - This will prevent matching any of the defined options.
A lookahead is a zero-length assertion that can be used at a any position in a string.

  • Related