mifflin has asked for the wisdom of the Perl Monks concerning the following question:
I have some data files that were created without newlines that need to be fixed.
The files contain a bunch of records with an xml file name at the end.
They look like...
somedata file.xmlsomedata file.xmlsomedatafile.xml ....
what I want them to be is ...
somedata file.xml
somedata file.xml
somedata file.xml
...
So , i thought I could use a piecewize regex like so...
The files contain a bunch of records with an xml file name at the end.
They look like...
somedata file.xmlsomedata file.xmlsomedatafile.xml ....
what I want them to be is ...
somedata file.xml
somedata file.xml
somedata file.xml
...
So , i thought I could use a piecewize regex like so...
The problem is I cannot figure out how to make the regex non-greedy. My capturing portion matches the full string, all the way to the last xml file. How to I change the regex to be non-greedy and match up to the first xml file?pos $data = 0; my $len = length $data; while (pos $data < $len) { if ( my ($line) = $data =~ m{ \G ( .+ \. xml ) }gcxms ) { print "$line\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: non-greedy piecewise matching
by ikegami (Patriarch) on Aug 02, 2007 at 17:40 UTC | |
by mifflin (Curate) on Aug 02, 2007 at 19:12 UTC | |
Re: non-greedy piecewise matching
by NetWallah (Canon) on Aug 02, 2007 at 16:56 UTC | |
by mifflin (Curate) on Aug 02, 2007 at 17:24 UTC | |
Re: non-greedy piecewise matching
by FunkyMonk (Chancellor) on Aug 02, 2007 at 16:58 UTC | |
by mifflin (Curate) on Aug 02, 2007 at 17:02 UTC | |
Re: non-greedy piecewise matching
by roboticus (Chancellor) on Aug 02, 2007 at 23:04 UTC | |
Re: non-greedy piecewise matching
by prasadbabu (Prior) on Aug 02, 2007 at 17:03 UTC |
Back to
Seekers of Perl Wisdom