You need to provide more context, but I suspect you are trying to parse one line at a time, but match strings that span several lines.
I strongly suggest that you use a module such as XML::Twig to parse XML! Consider:
use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new (twig_roots => {content => \&contents}); my $xml = do {local $/; <DATA>}; $twig->parse ($xml); sub contents { my ($twig, $contents) = @_; my @children = $contents->children (); my @wanted = qw(id title published); my $match = join '|', @wanted; my %params; for my $child (grep {$_->tag () =~ /^($match)$/} @children) { $params{$child->tag ()} = $child->text (); } print join "\t", @params{@wanted}; } __DATA__ <data> <content> <id>http://gdata.youtube.com/feeds/api/videos/5InqyMvRZ8o/comm +ents/7307D6E7F6E2D1B8 </id> <published>2007-04-05T12:05:42.000-07:00 </published> <updated>2007-04-05T12:05:42.000-07:00 </updated> <category scheme='http://schemas.google.com/g/2005#kind' term= +'http://gdata.youtube.com/schemas/2007#comment'/> <title type='text'>Fantastisk video,, ... </title> Keep up the good work. - jeg glder mig meget til at se flere +videoer fra dig..uper billeder du har fundet (: </content> <link rel='related' type='application/atom+xml' href='http://gdata +.youtube.com/feeds/api/videos/5InqyMvRZ8o'/> <link rel='alternate' type='text/html' href='http://www.youtube.co +m/watch?v=5InqyMvRZ8o'/> <link rel='self' type='application/atom+xml' href='http://gdata.yo +utube.com/feeds/api/videos/5InqyMvRZ8o/comments/7307D6E7F6E2D1B8'/> <author> <name>cajaneil </name> <uri>http://gdata.youtube.com/feeds/api/users/cajaneil </uri> </author> </data>
Prints:
http://gdata.youtube.com/feeds/api/videos/5InqyMvRZ8o/comments/7307D6E +7F6E2D1B8 Fantastisk video,, ... 2007-04-05T12:05:42.000-07:00
Note that I altered the XML to make it valid and that I chose elements that exist as children of content for demonstration purposes. You will need to alter the code to suit what you are actually doing.
In reply to Re: trouble with regular expressions, dont know why patters aren't matching
by GrandFather
in thread trouble with regular expressions, dont know why patters aren't matching
by downer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |