Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Keeping lookahead assertion from looking to the end of the string?

by Django (Pilgrim)
on Sep 05, 2002 at 07:23 UTC ( [id://195300]=note: print w/replies, xml ) Need Help??


in reply to Keeping lookahead assertion from looking to the end of the string?

If you just want to check if the string matches, Limbic~Regions example will probably do it.

Although you didn't say it, I suppose you want to catch the substrings between 'start' and 'end' - otherwise you don't have to care about overlapping. In that case you could do something like the following:

#!usr/bin/perl use warnings; $_ = "start b2 end start b2 b2 end start b2 end"; @Matches = / # list context to catch all (?<= \b start \b )# 'start' must precede ( .*? ) # catch fewest possible anythings (?= \b end \b )# 'end' must follow /gx # global and expressive and print join("\n", @Matches); __DATA__ b2 b2 b2 b2

update: normal matching without look-ahead and look-behind will have the same effect with the example string:

@Matches = / \b start \b ( .*? ) \b end \b /gx

update: I overlooked that Limbic~Regions regex catches the substring too. Shame on me!

~Django
"Why don't we ever challenge the spherical earth theory?"

Replies are listed 'Best First'.
Re: Re: Keeping lookahead assertion from looking to the end of the string?
by Anonymous Monk on Sep 05, 2002 at 12:04 UTC
    Um, my RegEx does catch the substring between "start" and "end" as depicted in the print statment. As always, TIMTOWTDI.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://195300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-19 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found