/(?:(?!$re).)*/
is the equivalent of
/[^$chars]*/
but it can (negatively) match entire regexps instead of a choice of characters. Keep in mind that both expressions can sucessfully match 0 characters if not properly anchored.
s/(.*ing)(?:(?!bob|fred|bill).)*(more)/\1HIT\2/;
Update:
You may want
"something that isn't /bob|fred|bill/"
rather than
"something that doesn't contain /bob|fred|bill/".
The code for that would be:
s/ (.*ing) (?: .{0,2} | (?!bob).{3} | (?!fred|bill).{4} | .{5,} ) (more) /\1HIT\2/x;
or
my %bad_words = map { $_ => 1 } qw( bob fred bill ); s/ (.*ing) (.*) (?(?{ $bad_words{$2} })\A(?!\A)) (more) /\1HIT\3/x;
You could simplify the above to
s/(.*ing)(?!bob|fred|bill).*(more)/\1HIT\2/;
but only if the start of more can't match the end of bob, fred or bill.
In reply to Re: Negating a regexp
by ikegami
in thread Negating a regexp
by jxh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |