[Tfug] Regex poser

Bexley Hall bexley401 at yahoo.com
Thu Nov 5 10:52:37 MST 2009


Hi Chris,

> 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>
> >>>

Yes!
 
> 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!)

Unfortunately, this syntax isn't supported in flex(1).
 
> Bexley, we both know you're a smart programmer

No, I am a pimply-faced, 14-year-old adolescent that is
overly shy and takes refuge in computers because the girls
all think I am a nerd...  wanna play with my Star Wars action
figures??  You can be Chewbacca if you want... :)

> 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. :-)

Aw, shucks...


      




More information about the tfug mailing list