Galen has asked for the wisdom of the Perl Monks concerning the following question:
How does one extract the middle of a string with a regular expression, given the characters before and after the substring desired? For example, let's say I need to isolate all characters between "abc" and "xyz"...
I can do this with index and substr, but regex has got to be more efficient. Thanks in advance :)$foo = "abchelloxyz"; $bar = /regex on $foo/; # $bar = "hello"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(wil) Re: regex: extract a substring
by wil (Priest) on May 23, 2002 at 20:38 UTC | |
by krujos (Curate) on May 23, 2002 at 21:28 UTC | |
by Hofmator (Curate) on May 24, 2002 at 17:07 UTC | |
by insensate (Hermit) on May 23, 2002 at 23:12 UTC | |
|
Re: regex: extract a substring
by derby (Abbot) on May 23, 2002 at 20:39 UTC | |
|
Re: regex: extract a substring
by Galen (Beadle) on May 23, 2002 at 22:27 UTC | |
by sfink (Deacon) on May 24, 2002 at 04:16 UTC |