Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: REGEX issue

by sanPerl (Friar)
on May 29, 2007 at 07:35 UTC ( #617922=note: print w/ replies, xml ) Need Help??


in reply to REGEX issue

I can suggest some different method
This will ensure that <image> is NOT embeded into any <story> tag.

use strict; my $str = "<story> <page> <description> desc </description> <story>aaaaaaaaa</story> <image> notExpected.jpg </image> <headline> head </headline> </page> </story> <story>aaaaaaaaaaaa <image> notExpected.jpg </image> aa</story> <image>correctImage.jpg</image> "; while ($str =~ m/<image>(.*?)<\/image>/gs) { my ($image_content) = ($1); my $story_st=0; my $story_en=0; my $prelines = $`; while ($prelines =~ m/<story>/gs){$story_st++} while ($prelines =~ m/<\/story>/gs){$story_en++} print $image_content, "\n" if ($story_st == $story_en); }


Comment on Re: REGEX issue
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://617922]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-07-05 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls