JS извлекать только числа из строки
"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')
// Response: "123456789"
Tarik
"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')
// Response: "123456789"
thenum = "foo3bar5".match(/\d+/)[0] // "3"
str = "hello123!"
str.match(/(\d+)/)[1] //Best way to find first matching number in string ;)
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
var regex = /\d+/g;
var string = "Any string you want!";
var matches = string.match(regex); // creates array from matches
if (matches){
// There is a digit in the string.
} else {
// No Digits found in the string.
}
// Html: <span id="foo">280ms</span>
var text = $('#foo').text();
var number = parseInt(text, 10);
alert(number);
// parseInt('ms120'.replace(/[^0-9\.]/g, ''), 10);