A regular expression query

D

Devon_Dan

First, thanks for taking the time to read this post. I have spent a
while trying to make this work but to no avail and I cant find a post
that explains it. Your time is appreciated.

Now I have a text file with a large amount of XML data in it. I am
trying to extract everything between <Folder>...</Folder> tags. These
extend over a number of lines and there are an undefined number of
these folders in the file. I would like the contents of each of the
folders to be assigned to a either a new variable or part of an array.
Something like:

$result[1] = "contents of folder one";
$result[2] = "contents of folder two"; etc...

I have the contents of the text file as a single variable $content and
I think I have the right regular expression to match the first folder:

$content =~ m/<(F|f)older>t.*?<\/(F|f)older>//s

Still I am unsure how to loop through and collect each of the
instances.

Any tips or hints? Perhaps its a basic hole in my understanding and
someone can even recommend a good tutorial/article that explains it?

Thanks

Dan
 
J

Jürgen Exner

Devon_Dan said:
First, thanks for taking the time to read this post. I have spent a
while trying to make this work but to no avail and I cant find a post
that explains it. Your time is appreciated.

Now I have a text file with a large amount of XML data in it. I am
trying to extract everything between <Folder>...</Folder> tags.

Any of the XML modules should be able to handle this task easily, e.g.
XML::Simple or XML::parser
I have the contents of the text file as a single variable $content and
I think I have the right regular expression to match the first folder:

$content =~ m/<(F|f)older>t.*?<\/(F|f)older>//s

Still I am unsure how to loop through and collect each of the
instances.

Maybe you are just looking for the g option (perldoc perlop, 'Regexp
Quote-Like Operators').
Any tips or hints? Perhaps its a basic hole in my understanding and
someone can even recommend a good tutorial/article that explains it?

Use the proper tool for the job. REs are not the proper tool for parsing
XML.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top