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
In reply to Re: extracting a substring from a string - multiple variables
by mwah
in thread extracting a substring from a string - multiple variables
by walinsky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |