CrazySynthax
CrazySynthax

Reputation: 15048

Javascript: How to remove symbols that do not represent number

I got the following string in UTF-8 encoding:

&#8364 ;64.95

The "&#8364" represents a Euro currency sign. I want to write code that erases all UTF-8 characters that are not '.' and/or a digit. Do you know how to do it?

Upvotes: 0

Views: 27

Answers (1)

Xotic750
Xotic750

Reputation: 23492

You are scraping HTML and what you have posted is an example of an escaped character for use in HTML. If you are not interested in unescaping this character, but just removing it, then something as simple as the following should suffice.

const str = '€64.95';
const after = str.replace(/&#\d*;/gm, '');
console.log(after);

Upvotes: 1

Related Questions