[Tfug] Regex poser

Chris Niswander MOST.SENDERS.ARE._FILTERED.OUT_--FOR.MY.REAL.EMAIL.ADDRESS.check.my.website..tfug.rcvr.x6a3 at bitboost.com
Thu Nov 5 03:42:20 MST 2009


Hi, Bexley!

I think I understand what you want.

One way of accomplishing this is with
a tool that has the amusingly non-simple name of
a 'negative lookbehind assertion'.

I'll give simpler examples
that show how to do what you want in Python and Perl.

Suppose you want the regular expression "[1-3][4-6]"
but you DO NOT want to match the specific string "25".

In *Python*,

 >>> p3 = re.compile("[1-3][4-6](?<!25)")
 >>> p3.match("14")
<_sre.SRE_Match object at 0x010B06E8>
 >>> p3.match("26")
<_sre.SRE_Match object at 0x010B06B0>
 >>> p3.match("25")
 >>> p3.match("35")
<_sre.SRE_Match object at 0x010B06E8>
 >>>

In *Perl*, the negative lookbehind assertion syntax
also has an equals sign, so I *think* the equivalent
regex would be [1-3][4-6](?<!=25)
(I didn't test this!)

Bexley, we both know you're a smart programmer
and you can easily adapt this trick to your exact problem
without my finishing it for you. :-)

The principle also holds for some person unlike you, trying to get
someone to do their homework for them. :-)

--Chris Niswander

Bexley Hall wrote:
> Hi,
> 
> I want a regex that is essentially
> 
> [\x20-\x60][\x80-\xFF][\x60-\xDF]
> 
> but *excludes* \x22\x83\x78
> 
> Tricks?
> 
> 
>       
> 
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
> 





More information about the tfug mailing list