Link to home
Start Free TrialLog in
Avatar of PurpleSlade
PurpleSlade

asked on

unmatched ) in regex

I have a tag in an xml document of:
<DOI>10.6483/ceeec.2012.104.0001</DOI> 

Open in new window

that I want to replace with
<DOI>http://dx.doi.org/10.6483/ceeec.2012.104.0001</DOI>

Open in new window


when the code gets to here
if ($rec =~ /<DOI>(ceeec.*)<\/DOI>)/i)
{
    $doi = $1;
    $doi =~ s/$doi/http:\/\/dx\.doi\.org\/10\.6483\/$doi/;
    $rec =~ s/<DOI>.*<\/DOI>/$doi/;
}

Open in new window


I get the message
Unmatched ) in regex; marked by <-- HERE in m/<DOI>(ceeec\.\*)</DOI>) <-- HERE /
 at changeDOI.pl line 26.

Open in new window


Any advice on the way to properly solve this?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#or maybe
$rec =~s#(?<=<DOI>)(?=((?!</DOI>|http:).)*ceeec)#http://dx.doi.org/#i
Well it's just as the error message states:  you have one opening paren:

...DOI>(ce...

but two closing parens:

... .*)<\/DOI>)/i...

One of those either needs to go away, or you need to add another opening paren.
Avatar of PurpleSlade
PurpleSlade

ASKER

This got me to the best solution for my problem.  Thanks!
$rec =~ s#(<DOI>)ceeec(.*?</DOI>)#$1http://dx.doi.org/10.6483/ceeec$2#i;