[Linux-disciples] Negative Perl Regexp

Adam Rosi-Kessel adam at rosi-kessel.org
Thu Jul 22 15:56:07 EDT 2004


On Thu, Jul 22, 2004 at 03:32:15PM -0400, Chung-chieh Shan wrote:
> On 2004-07-22T14:26:11-0400, Adam Rosi-Kessel wrote:
> > This should be easy, but I've looked at perlre and am stuck.
> Really?  Search for "negat" in perlre perhaps?

I did that, and got almost all the way there, but not quite.  I was
trying /(?!pattern)/ and /(?<!pattern)/ but this only worked if the whole
string was "not" the pattern.

>     /\A(?:(?!ab).)*\z/
> (Untested.)

That seems to do the job, thanks.  I was missing the key element of \A
and \z (which presumably is the same as ^/$ except in multiline strings),
and the repeat operation.

I guess I'm not entirely sure why the . is in there, though. Based on
experimenting just now, if I omit the . then the negative fails, I guess
because (?!ab) means "not ab" but you need to have something else in
there to match?  I'm having trouble expressing this--is it that the
(?!ab) collapses into nothingness for the purpose of the (?:) unit? Hmm.

It's good to have you back, anyway.
-- 
Adam Rosi-Kessel
http://adam.rosi-kessel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20040722/328aeba4/attachment.pgp


More information about the Linux-disciples mailing list