Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: can I make my regexp match first pattern instead of last?

by dreadpiratepeter (Priest)
on Oct 26, 2008 at 12:37 UTC ( [id://719637]=note: print w/replies, xml ) Need Help??


in reply to Re^4: can I make my regexp match first pattern instead of last?
in thread can I make my regex match first pattern instead of last?

You aren't putting any bounds on what it throws away when looking for your tag. Here is a more simple example. Here's the data:
a=1,b=2,a=2,a=3,b=4
If you search using /b(.+?)4/, you will match b=2,a=2,a=3,b=4 because the .+? expression doesn't care about what it discards to find your match.
In your code above, you match the first ELEMENT tag, but your .+? expressions only care about the part number; that is why they eat multiple ELEMENT tags on their way to it.
while you could do your match using very convoluted and fragile regexes, it is better to do it programatically. Since you only want to match within 1 record of your data, the first step should be splitting the input into records (demonstrated in another responce). then your regexes will be limited to just the 1 record you are searching


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found