JS extrai apenas números da string
"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"
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
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);