in reply to Problem with Regex

A solution using a pure-Perl XML parser:

use strict; use warnings; use Mojo::DOM; my $dom = Mojo::DOM->new()->parse(do { local $/; <DATA> }); # here you can use any other tag than 'title' too: print $dom->at('title')->text; __DATA__ <page> <title>Some Title</title> <id>1149707</id> <revision> <id>4220</id> <timestamp>2011-04-02T16:47:40Z</timestamp> <contributor> <username>some User Name</username> <id>268</id> </contributor> <minor /> <text xml:space="preserve">some Text ... ......... ..................... ..................... .....................</text> </revision> </page> <page> <title>Some other Title</title> <id>11497077</id> <revision> <id>42290</id> <timestamp>2011-05-02T16:47:40Z</timestamp> <contributor> <username>some Other User Name</username> <id>2688</id> </contributor> <minor /> <text xml:space="preserve">some Other Text ... ......... ......... ..................... ..................... .....................</text> </revision> </page>

See Mojo::DOM for other extraction methods it offers.

Replies are listed 'Best First'.
Re^2: Problem with Regex
by &#350;uRvīv&#337;r (Novice) on Aug 01, 2011 at 13:09 UTC

    thanks a lot for your help, I used the XML::DOM XML parser, it's easy to use, but I'm still having a problem with finding matches in a multi-line string. For Example, I wanna look for a category in a multi-line text:

    [category: SOME CATEGORY]

    How do i do that !!!

      actually .. I wanna find all categories in a certain text
        What is a "category" in that context? I don't understand what you want to extract, and why this is suddenly different from your original question (which seemed to be to find the contents of the first tag with a specific name).