in reply to positive regex for inverted match

Just set the match to be exactly zero times.

print "$_" if $_ =~ /(bar){0}/;

- - arden.

Update: Thanks hossman++, this is proof you shouldn't attempt regexes at 3am when you're sleep-walking.

Replies are listed 'Best First'.
Re: Re: positive regex for inverted match
by hossman (Prior) on Feb 26, 2004 at 07:24 UTC

    Uh, no.

    That will match every string, because "bar" 0 times is the empty string, and every input matches the empty string.

    laptop:~> perl -le 'print "matches" if "bar" =~ /(bar){0}/;' matches laptop:~> perl -le 'print "also matches" if "barbar" =~ /(bar){0}/;' also matches laptop:~> perl -le 'print "event this matches" if "" =~ /(bar){0}/;' event this matches