javascript extract number from string
"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')
// Response: "123456789"// Html: <span id="foo">280ms</span>
var text = $('#foo').text();
var number = parseInt(text, 10);
alert(number);
// parseInt('ms120'.replace(/[^0-9\.]/g, ''), 10);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.
} thenum = "foo3bar5".match(/\d+/)[0] // "3"
Also in JavaScript:
- how to check if enter is pressed javascript
- how to Check if an array contains a string
- javascript querySelectorAll to array
- Javascript modify URL without reload
- javascript detect browser type
- how to scroll to an element javascript react
- generate random number nodejs
- node js list all installed modules
- javascript array reorder elements
- javascript remove parameters from current url
- implement the remove property function
- javascript wait 5 sec
- angular trigger input change
- chartjs start at 0
- invalid left-hand side in assignment
- javascript on hover
- filter
- import library react js
- string contains string javascript
- jquery selector parent on hover
- express validator
- lodash find object in array
- adonis migration column char
- How to check if a member has a role discord.js