tintin tintin - 2 months ago 20
Javascript Question

Regex using Hexcode for Euro symbol

I want to write a regex expression for Euro currency symbol.

I wrote

but its not working. Any ideas how to get it matching?


The /[x80]/g is not working because the [...] is a character class matching 1 char from the defined set: either x, 8 or 0.

You need to either use the literal (/€/g), or, in case there are issues with using the literal euro symbol, you should use /\u20AC/g.

var s = "1.500€ - 2.000€";
console.log(s.replace(/\u20AC/g, "EUR"));