I'm using a negative lookbehind regex, like so:
if ($foo =~ /(?<!most\s)wanted/i) {
...
}
The goal is to match if $foo contains "wanted", but only if it is not preceded by "most\s".
The error I'm getting is:
Variable length lookbehind not implemented in regex m/(?<!most )wanted/ (Note, I removed the \s for testing and it didn't help)
I've found this being discussed as far back as 2013, and maybe it's a bug in Perl? I'm not sure:
[
stackoverflow.com...]
Either way, can you suggest a fix, or a better way to do what I'm wanting?
I found that I could use \K for positive lookbehind, but not negative:
[
regular-expressions.info...]
The only alternative I can think of is to set another variable to remove "most wanted" from $foo, then test; eg:
($bar = $foo) =~ s/most wanted//g;
if ($bar =~ /wanted/i) { ... }
But I've used this in several sections, which means several unnecessary placeholder variables. I'm trying to avoid unnecessary variables when I can to speed things up, so before I do that is there a better way?