[Linux-disciples] Negative Perl Regexp

Chung-chieh Shan ccshan at post.harvard.edu
Thu Jul 22 15:32:15 EDT 2004


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?

> Does anyone know how to make a regexp that only returns true if there is
> no match in perl, assuming you don't have access to the surrounding code,
> just the regexp?

You can always do it, even without the negation stuff in perlre, for
"true" regular expressions (i.e., those for languages recognizable by a
finite automaton).  For example,

    not /ab/

is like

    /\A[^a]*((a+[^ab])+[^a]*)*a*\z/

but it's easier to do it with

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

(Untested.)

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Able was I ere I saw Elba.
An ole crab was I ere I saw Barcelona.
http://tinyurl.com/5rxn9 Ministry of Peace Bill
http://tinyurl.com/3rc7f Local Communities Sustainability Bill
-------------- 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/132ff046/attachment.pgp


More information about the Linux-disciples mailing list