Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: regular expression ignores two lines

by Crackers2 (Vicar)
on Aug 20, 2009 at 12:48 UTC ( #790084=note: print w/ replies, xml ) Need Help??


in reply to Re^2: regular expression ignores two lines
in thread regular expression ignores two lines

Because your regex is anchored to the start and end of the string, so it'll only find a tag that's on a line by itself:

if (/^\{(.*)\}$/) { $tag = $1; print "The tag is $tag\n"; }

Your {TTL} and {LINE} tags are in the middle of the line, so they won't get picked up by the regex.

You could try something like this instead:

while (/\{(.*?)\}/g) { $tag = $1; print "The tag is $tag\n"; }

Output:

The tag is SOURCETAG The tag is DATE The tag is EDITION The tag is HEADLINE The tag is SOURCE The tag is LINE The tag is TTL


Comment on Re^3: regular expression ignores two lines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-11-29 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (204 votes), past polls