[San-Diego-pm] Regular Expressions: zero-width negative look-behind assertion

Douglas Wilson dgwilson1 at cox.net
Mon Jan 31 11:59:18 PST 2005



Bill Davidson wrote:
> I'd like to use a zero-width negative look-behind assertion for something
> I'm working on.  Unfortunately, for some reason, the implementers of
> Perl's RE engine decided that it should only be able to do a fixed width
> look-behind.
> 
> I'd like to do this:
> 
>     if ( $myvar =~ /(?<!foo\d+)bar$/ ){

If you want to match at the end of the line, you can
reverse the string and then use a negative lookahead
assertion.

-Doug



More information about the San-Diego-pm mailing list