Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 studying the Monastery: (4)
As of 2014-10-24 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (130 votes), past polls