I have string in the bellow format:
let str = "url(#123456)";
My string have only number contain in it. It can be any where.
I want to extract the number 123456
from the above string.
I am using es6.
I have string in the bellow format:
let str = "url(#123456)";
My string have only number contain in it. It can be any where.
I want to extract the number 123456
from the above string.
I am using es6.
str.replace(/[^0-9]/g, '')
let str = "url(#123456)";
console.log(str.replace(/[^0-9]/g, ''))
another way to do it
let str = "url(#123456)";
console.log(str.match(/\d+/)[0])
I did it in a way too complicated way, but it does not involve regex so it's probably better to understand:
let str = "url(#123456)";
str = str.split("#");
str = str[1].split(")");
str = str[0];
console.log(str);
Using only Array methods:
console.log("url(#123456)".split('#').pop().slice(0, this.length -1))