Hello cryion, and welcome to the Monastery!
With the XML data shown, the regex you say doesn’t work actually does, as long as there is no /s modifier, because in the absence of that modifier . won’t match a newline character — and therefore the matching file: has to be on the same line as the \.xml.
But I’m guessing that your real data doesn’t always contain newlines as in the example. In that case, you can use a technique which I learned here at PerlMonks:
#! perl use strict; use warnings; my $xml = '<xml><info><file>file:/path1/to/some/file.mxf</file></in +fo>' . '<info><file>file:/path2/to/some/file.xml</file></info></ +xml>'; my $lmx = reverse $xml; my ($htap) = $lmx =~ /lmx\.(.*?):elif/s; if (defined $htap) { my $path = reverse $htap; print "Path: $path\n"; }
Output:
23:32 >perl 1335_SoPW.pl Path: /path2/to/some/file 23:32 >
See reverse.
Update (Aug 11, 2015):
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Regex match: Ignoring first occurrences
by Athanasius
in thread Regex match: Ignoring first occurences
by cryion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |