Search code examples
javascriptregexreplacestr-replace

Javascript How to remove Japanese/Chinese Yen symbol


No idea why this doesn't work since I can obviously remove other symbols this way but this: str = str.replace('¥', ''); fails to remove the symbol ¥ in question. Any ideas how to remove this thing?

I've also tried this str = str.replace(/¥/g, ''); and this str = str.replace(/\¥/g, ''); to no avail.

Obviously I can remove it by just knocking of the first character in the string but I thought there must be a way to actually detect this thing just in case it's not at the front and I need to remove it.


Solution

  • There are multiple unicode code points for yen symbol: https://en.wikipedia.org/wiki/Yen_sign

    try str.replace(/[¥¥]/g, '')