in reply to Storing String from Line Before Regex Match
Hi Nico,
I like toolic's approach better, but in the spirit of TIMTOWTDI:
my $re = qr/ First\ Name: \s+ (.+)\n Last\ Name: \s+ (.+)\n (?:.+\n)* Location:\ Central\ USA\n /x; while ($line=~/$re/g) { print "<$1> <$2>\n"; }
Note the use of the /x modifier to make the regex more readable. Also, I removed the /s modifier, so that the dot . doesn't match newlines.
I think this approach is probably a little less robust than splitting the input file on empty lines, but if you're sure of the formatting of the input files this should still work.
Hope that helps,
-- Hauke D
|
|---|