swackerl has asked for the wisdom of the Perl Monks concerning the following question:
An explanation of what I'm trying to match is a substring of $str where it is made up of an 'start' marker, followed by two 'b2' markers, followed by an 'end' marker (with any text, not just whitespace, interspersed between the markers that I've mentioned). Think of 'start' as marking the start and 'end' marking the end of the possible string. I DON'T want the expression to overlap between two strings such as in: "start b2 end start b2 b2 end" where the matched string contains an additional 'start' marker. I've tried doing this with look-ahead and look-behind assertions. The problem with a lookahead assertion is that it will search to the end of the string, so if there is any 'start' AFTER the string that I want to match, no matches will be found. The problem with a lookbehind assertion is that it does not allow for variable length strings. Can anyone help me solve this difficult problem?my $str = "start b2 end start b2 b2 end start b2 end"; if ($str =~ /start(?!.*start.*)(.*?b2.*?b2.*?end)/) { print "Regexp matched!"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Keeping lookahead assertion from looking to the end of the string?
by VSarkiss (Monsignor) on Sep 05, 2002 at 03:34 UTC | |
|
Re: Keeping lookahead assertion from looking to the end of the string?
by Limbic~Region (Chancellor) on Sep 05, 2002 at 04:58 UTC | |
by swackerl (Initiate) on Sep 05, 2002 at 18:22 UTC | |
by swackerl (Initiate) on Sep 05, 2002 at 22:48 UTC | |
by jsprat (Curate) on Sep 05, 2002 at 22:06 UTC | |
|
Re: Keeping lookahead assertion from looking to the end of the string?
by Django (Pilgrim) on Sep 05, 2002 at 07:23 UTC | |
by Anonymous Monk on Sep 05, 2002 at 12:04 UTC |