To employ a regular expression to get a number within a string, we can use
\d+:const string = "x12345david";
const [match] = string.match(/(\d+)/);
match; // 12345
Regular expressions are capable of really powerful operations within JavaScript; this practice is one of the easier operations. Converting the number using a
Number() wrapper will give you the number as a Number type.The post Extract a Number from a String with JavaScript appeared first on David Walsh Blog.
https://tkjs.us/dwb
https://davidwalsh.name/javascript-extract-string
