I want to use regular expressions (Perl compatible) to be able to find a pattern surrounded by two other patterns, but not include the strings matching the surrounding patterns in the match.
For example, I want to be able to find occurrences of strings like:
Foo Bar Baz
But only have the match include the middle part:
Bar
I know this is possible, but I can't remember how to do it.
Parentheses define the groupings.
"Foo (Bar) Baz"
Example
~> cat test.pl
$a = "The Foo Bar Baz was lass";
$a =~ m/Foo (Bar) Baz/;
print $1,"\n";
~> perl test.pl
Bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With