function justNumbers(string) {
var numsStr = string.replace(/[^0-9]/g, '');
return parseInt(numsStr);
}
var input = "Rs. 6,67,000";
var number = justNumbers(input);
console.log(number); // 667000
Run code snippet
thenum = "foo3bar5".match(/d+/)[0] // "3"
str = "hello123!"
str.match(/(d+)/)[1] //Best way to find first matching number in string ;)
const extractNumbers = (string) => {
const regex = /[0-9/ /]/g;
const nums = string.match(regex);
const newText = nums.join("");
return newText
};
// Html: <span id="foo">280ms</span>
var text = $('#foo').text();
var number = parseInt(text, 10);
alert(number);
// parseInt('ms120'.replace(/[^0-9.]/g, ''), 10);