So, I have a string something like, asd.asd.asd.234432$$..asd888. Now I want to get a string like, .234432888. So what I want to achieve is to remove every dots except for the first one and remove every non number character.
So far I tried *string*.replace(/[^\d.]/gi, new String()). But, it does not work as expected.
>Solution :
Do a global regex match of characters:
(?<!\..*)– find.that doesn’t have.before it at any distance (.*) using a lookbehind negative assertion. That would be the first.encountered.\d+– find all numbers- join the found characters:
const str = 'asd.asd.asd.234432$$..asd888';
console.log(str.match(/(?<!\..*)\.|\d+/g).join(''));