Link to home
Start Free TrialLog in
Avatar of PurpleSlade

asked on

unmatched ) in regex

I have a tag in an xml document of:

Open in new window

that I want to replace with

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 line 26.

Open in new window

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

Link to home
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)#
Well it's just as the error message states:  you have one opening paren:


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


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