Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: REGEX issue

by sanPerl (Friar)
on May 29, 2007 at 07:35 UTC ( [id://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); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-23 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found