3
Answers

Need help on replace using regular expression

Edgar Santos

Edgar Santos

16y
7.9k
1
Hi.

I have the following string "aaaaaa££aaaaa£aaaaa££"
and i want to replace £ for € and ££ for £.
(the string may change, but the rules are the same)

i've tried doing the following :
stringvar.replace(/[£]/g,"\u20AC")).replace(/[££]/g,"£")

It's obvious that the first replace replaces all £ by €..so the second replace never happens.

I'm trying to find a regular expression that helps me on this case, like saying to the replace that if he find a £ isolated from other £ he can replace for €. If not replace with £.

Hope you can help.

Cheers.
Answers (3)