js get numbers from string
"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')
// Response: "123456789"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.
}const thestring = "1 fish 2 fish red fish blue fish";
const thenum = thestring.replace( /^\D+/g, ''); // replace all leading non-digits with nothing
console.log(thenum); //Output: 12
Also in JavaScript:
- Line 6:3: Expected an assignment or function call and instead saw an expression no-unused-expressions
- react native text input next field hooks focus
- how to declare 3d array in javascript
- angular mouseenter
- jwt refresh token
- mongoose database pooling
- example formidable multiple image upload
- Discord embeds
- javascript var in quotes
- angular formarray remove all
- how to destructure complex objects
- model to js
- javascript findindex
- timing code in javascript
- ajax call to load a page on scrolling
- sort function in react js
- check if a class exists javascript
- react datepicker
- js xmlhttprequest add header
- export default arrow function
- datatable loading
- inverser l'ordre des item d'un array js
- mutable array methods in javascript
- how to create a server in node js