homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum


5+ Year Member

Msg#: 3789987 posted 10:09 pm on Nov 19, 2008 (gmt 0)

I am really struggling to come to terms with look-ahead and look-behind concepts in Regular Expressions.

I am new to Perl and can only start to get an understanding with maybe an example that explains how these concepts work.

Can anyone help me with this?



WebmasterWorld Administrator ergophobe us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 3789987 posted 6:13 pm on Nov 21, 2008 (gmt 0)

The lookahead is a 'zero width' expression so it allows you to see if you have a match, without having to capture the characters you're matching. So for example

a[^b] - matches "a" and whatever character follows an "a" as long as it's not a "b"

a(?!b) - matches "a" and only "a" provided that it is not followed by a "b" but it does not match the character after the "a".

So for example in "example" the first expression would capture "am" and the second would capture "a".

I'm trying to think of a case where you can't do it any other way, but I'm not coming up with one. You'll see, sometimes, that a negated character class won't get the job done though.

Example anyone?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved