in reply to extracting a substring from a string - multiple variables
Nobody answered after 16 min? Oh, graff did (and was faster than me) ;-)
... my ($fiop, $length, $data) = $string =~ m{<file # tag anchor \s+ fiop="([^"]+)" # (foo) \s+ length="([^"]+)" # (bar) /> # end: start file tag \s* (.*?) # (baz) - note the "nongreedy +ness" .*? </file> # end: file tag }x; print "$fiop, $length, $data\n"; ...
Addendum: forgot the tag-cleaning part:
... (my $notags = $string) =~ s{<file.+?</file>}{}; print "$notags\n"; ...
Your mistake was basically to take the "greedy modifier" (.*), which matches until the end of the string - and backtracks then - and matches from the rear ...
Regards
mwa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extracting a substring from a string - multiple variables
by walinsky (Scribe) on Oct 27, 2007 at 23:23 UTC | |
by mwah (Hermit) on Oct 28, 2007 at 00:24 UTC | |
by walinsky (Scribe) on Oct 28, 2007 at 01:07 UTC | |
by mwah (Hermit) on Oct 28, 2007 at 08:39 UTC | |
by walinsky (Scribe) on Oct 28, 2007 at 12:41 UTC | |
by mwah (Hermit) on Oct 28, 2007 at 16:19 UTC | |
by walinsky (Scribe) on Oct 28, 2007 at 18:57 UTC | |
|