i have regex - current.replace(/([^0-9]+)/gi, '');
How i can add here ₽
specific symbol? im trying current.replace(/([^0-9₽]+)/gi, '');
But this not working...
Asked
Active
Viewed 41 times
1
-
3It really depends on what you want to achieve. Please provide an example input and the desired output. "But this is not working..." is not a useful problem description. – Felix Kling Jul 26 '21 at 11:20
-
https://stackoverflow.com/questions/4374822/remove-all-special-characters-with-regexp – Jul 26 '21 at 11:21
-
I need to remove everything from the value except the spaces and the rub submbol ₽ – Jul 26 '21 at 11:23
-
if you want to remove everything bar the spaces and ₽ - what's the deal with `0-9`? you want to keep numbers as well? – Bravo Jul 26 '21 at 11:27
1 Answers
1
[^0-9₽]
means "NOT 0-9 or ₽".
To remove everything but keep spaces and ₽ do:
.replace(/[^ ₽]/gi, ''))
let string = "h 3 l l 0 ₽ h 4 l l 0";
console.log(".replace(/₽/gi, '') Will remove ₽:")
console.log(string + " > " + string.replace(/₽/gi, ''));
console.log(".replace(/[^0-9₽]/gi, '') Will remove everything that is not 0-9 or ₽:")
console.log(string + " > " + string.replace(/[^0-9₽]/gi, ''));
console.log(".replace(/[^ ₽]/gi, '') Will remove everything that is not SPACE or ₽:")
console.log(string + " > " + string.replace(/[^ ₽]/gi, ''));

Timothy Alexis Vass
- 2,526
- 2
- 11
- 30