bontchev has asked for the wisdom of the Perl Monks concerning the following question:
Hello enlightened ones,
I have a pretty basic problem, yet I am unable to find an elegant solution to it. :-(
I have a string which contains zero or more substrings, surrounded by delimiter pairs. I want to extract all the substrings.
For instance, if the delimiter pair is Foo and Bar and I have the string
WhateverFooBlahBarMoreFooStuffBarMoreI'd like to extract Blah and Stuff from it.
A simple
@words = ($line =~ /Foo(.*)Bar/g);doesn't work - because of the greedy expression matching it gets BlahBarMoreFooStuff. I tried to override that with
@words = ($line =~ /(Foo(.*)Bar)+?/g);but, for some reason, then I get FooBlahBarMoreFooStuffBar and BlahBarMoreFooStuff.
Any help would be appreciated...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting substrings
by kyle (Abbot) on Feb 17, 2008 at 12:30 UTC | |
|
Re: Extracting substrings
by ambrus (Abbot) on Feb 18, 2008 at 08:56 UTC | |
by ambrus (Abbot) on Feb 18, 2008 at 15:18 UTC | |
|
Re: Extracting substrings
by poolpi (Hermit) on Feb 18, 2008 at 10:26 UTC | |
by ambrus (Abbot) on Feb 18, 2008 at 15:25 UTC |