Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
The regex isn't really the question here, it's "how best to extract multiple instance of this pattern from one line"?
I'm using something like this:
$teststring = 'blah not-so-good blah not-too-shabby '; while($teststring =~ m/^.* ([a-z]+-[a-z]+-[a-z]+) .*$/i){ ($x = $teststring) =~ s/(^.* )([a-z]+-[a-z]+-[a-z]+)( .*$)/\2/gi; $teststring =~ s/(^.* )([a-z]+-[a-z]+-[a-z]+)( .*$)/\1 phrase \3/gi; print "$x\n"; }
because I don't know if there's a smarter way.
Obviously that print line would be used to push them into an array in a real life setting.
I have to keep going with a WHILE, because there may be more than one instance in a line, but surely there's a smarter way to do it than check there's a match, then extract it with one regex, then remove it from the test string with another?
|
|---|