Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: extract ids

by ww (Archbishop)
on Sep 16, 2009 at 04:57 UTC ( [id://795517]=note: print w/replies, xml ) Need Help??


in reply to extract ids

Your regex is close; very close.

However, the character class [A-Za-z] matches ONLY ONE character.

Since you want to match the many characters before the \smolecule, you need a quantifier after the char class, thusly:

if ($line =~ /^<[A-Za-z]+\smolecule_idref="(\d+)">$/) {

where the "+" says "Match one or more members of the class. (Note that even though the "+" makes the regex" greedy," there's no harm here, because you specify a whitespace character next.)

I've also changed your capture to specify one or more digits. .* matches ZERO or more of anything, which isn't what you've specified.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found