nzaleski nzaleski - 1 year ago 173
Perl Question

Negative Lookahead RegEx

Why is this not working? Trying to do a negative lookahead. I am trying to pull the numbers from the bins, except in quarantine bin and inspection bin. When I do the code with the ^ in the front is matches all numbers in parenthesis. When I remove the ^ it matches nothing.

Also can you use the "or operator |" inside the negative lookahead? I want to have ^(?!Quarantine_Bin|Inspection_Bin)

I also tried to specifically negate

and it is still matching.




Answer Source

You should be using a negative lookbehind as:


RegEx Demo

(?<!(Quarantine|Inspection)_Bin) is a negative lookbehind that asserts failure if there is Quarantine_Bin or Inspection_Bin before our match.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download