SlickEdit Product Discussion > SlickEdit®

Not operator not working in regular expressions


SlickEdit Pro 2021 (v26.0.1.0 64-bit Qt5)

it appears to me, as if following term is not working at all:

it positions on all lines and it is not supposed to position on the first line

slickedit regular expression mode:
sample term: ~(DEF)\\X90O0006

I think you want this regex:

--- Code: ---(#<!DEF)\\X90O0006

--- End code ---

The above regex essentially searches for \X90O0006 and asserts by a look behind that it is not preceded by DEF. Look behind operators should be used at the beginning of a regex. Look ahead operators should be used at the end of a regex.

The operator (~) you are using is a look ahead operator and will never work at the beginning of a regex. The docs don't explicitly say this but the example indirectly tells you it's a look ahead operator.

Look ahead and look behind operators are a pretty advanced part of regular expressions. They are extremely powerful once you know how to use them.

Note: SlickEdit supports variable length look behind. As far as I know, no other regular expression engine supports this (i.e. Perl doesn't support this).

Variable length look behind example:

--- Code: ---(#<!(DEF|H))\\X90O0006

--- End code ---

Thanks a lot Clark. You're right, I was not aware of this look behind / ahead concept.


[0] Message Index

Go to full version