Yes, it's possible. First you have to slurp in your input (ie, don't read line by line). Next, you need to set the /s modifier, and possibly /m for your regexp. /s tells the RE engine that '.' should match any character including a newline. /m tells the RE engine that $ and ^ should match at the beginning and ending of lines rather than beginning and ending of the string (that's what \A and \Z are for).
Also keep in mind that quantifiers such as * and + are greedy, so .* probably won't do what you want it to do when you hand it the following:
<tag>asdf</tag><tag>ghjkl</tag>Unless what you want is for it to be greedy.
my $string = "<tag>asdf</tag><tag>ghjkl</tag>"; if( $string =~ m{<tag>(.*)</tag>} ) { print $1, "\n"; } __END__ asdf</tag><tag>ghjkl
Woops!
Now introducing perlre! :)
Expect some replies telling you to use a proper XML parser, such as XML::Twig, XML::Parser, XML::LibXML, XML::Simple, etc. And they're right. Better to let a well tested solution do the work for you.
Dave
In reply to Re: regexp over multiple lines
by davido
in thread regexp over multiple lines
by liverpaul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |