Regular expressions:

var numberPattern = /\d+/g;

'something102asdfkj1948948'.match( numberPattern )

This would return an Array with two elements inside, '102' and '1948948'. Operate as you wish. If it doesn't match any it will return null.

To concatenate them:

'something102asdfkj1948948'.match( numberPattern ).join('')

Assuming you're not dealing with complex decimals, this should suffice I suppose.

Answer from meder omuraliev on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › extract-a-number-from-a-string-using-javascript
Extract a Number from a String using JavaScript - GeeksforGeeks
JavaScript · // Function to extract numbers function myGeeks() { // Input string let str = "jhkj7682834"; console.log(str) // Using match with regEx let matches = str.match(/(\d+)/); // Display output if number extracted if (matches) { console.log(matches[0]); } } // Function call myGeeks(); Output ·
Published: July 11, 2025
Discussions

Extract numbers from a string-Javascript - Code Review Stack Exchange
Consider the following string in javascript: var string="border-radius:90px 20px 30px 40px"; I want to extract the 4 numbers from that string and store them in an array called numbers.To do that I More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
January 5, 2016
regex - How can I extract a number from a string in JavaScript? - Stack Overflow
You can extract numbers from a string using a regex expression: More on stackoverflow.com
🌐 stackoverflow.com
regex - Extract all numbers from string in JavaScript - Stack Overflow
I want to be able to extract all numbers (including floating point) from a string in JavaScript. "-5. -2 3.1415 test 2.4".match(...) returns ["-2", "3.1415", "2.4"] So far I have /[-+]?(\d*\.?\... More on stackoverflow.com
🌐 stackoverflow.com
javascript regex - extract number from string - Stack Overflow
Given "1/2009 stay longer" or "34/1874 got to go", how can I get the digit right after the "/" using regex. '1/2009'.match(/\d+\/(\d)\d\d\d/g)[0] is returning 1/2009 which is not what I want. thx More on stackoverflow.com
🌐 stackoverflow.com
March 26, 2017
🌐
David Walsh
davidwalsh.name › javascript-extract-string
Extract a Number from a String with JavaScript
March 17, 2024 - There are multiple ways to get those numbers but let's rely on regular expressions to extract those numbers! 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.
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to extract a number from a string in javascript
How to Extract a Number from a String in JavaScript - Coding Beauty
June 30, 2022 - If we don’t pass the global flag, ... extract a number from a string, we can also call the match() method on the string, passing a regex that matches a consecutive sequence of digits....
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript extract number from string | regex & replace function example
JavaScript extract number from string | RegEx & Replace function example
May 16, 2021 - Simply use a regular expression in replace function to get numbers from string in JS. Regular expression for extracting a number is (/(d+)/)
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-extract-number-from-string
How to Extract a Number from a String in JavaScript | bobbyhadz
Use the `String.replace()` method to extract a number from a string, e.g. `str.replace(/\D/g, '')`.
Find elsewhere
🌐
Techstacker
techstacker.com › how to extract a number from a string with javascript
How to Extract a Number from a String With JavaScript – Techstacker
June 11, 2020 - Let’s say you have a string, that includes a number, and you want to extract only the number. No problem, you can use JavaScript’s match() method. Here’s a string value, containing one number (1995) that is assigned to a variable called stringWithOneNumber: const stringWithOneNumber = "JavaScript was invented in 1995 by Brendan Eich" Now let’s attach the match() method to the variable, and add \d+ as an argument, so it looks like this match(/\d+/) ... Note: \d+ is a regular expression (RegEx) meta character that means “match 1 or more digits”.
🌐
EncodedNA
encodedna.com › javascript › how-to-get-numbers-from-a-string-in-javascript.htm
How to Get Numbers from a String in JavaScript
I want to extract the number 4874 from the above string and there are two simple methods to this. Similar example: How to filter out only numbers in an Array using pure JavaScript · &ltscript> var tName = 'arun_4874'; alert(tName.match(/\d+/)); &lt/html> ... The metacharacter \d search for digits, which are also numbers.
🌐
Linux Genie
linuxgenie.net › home › how to extract/retrieve a number from string in javascript?
How to Extract/Retrieve a Number From String in JavaScript? - Linux Genie
June 11, 2023 - Call the replace() method with ... string: Another way for extracting a number from a string is to use the “match()” method with the regular expression....
🌐
TecHighness
techighness.com › home › how to extract numbers from a string in java script
How to Extract Numbers From a String in JavaScript - TecHighness
January 8, 2022 - const extractNumbers = (text, options) => { let numbers; options = options || {}; if (!text || typeof text !== "string") { return []; } numbers = text.match(/(-\d+|\d+)(,\d+)*(\.\d+)*/g); if (options.string === false) { numbers = numbers.map((n) => Number(n.replace(/,/g, ""))); } return numbers; };
🌐
Medium
medium.com › @tariibaba › javascript-extract-number-from-string-9b13aef29463
How to Extract a String from a Number in JavaScript | Medium
July 2, 2022 - If we don’t pass the global flag, ... extract a number from a string, we can also call the match() method on the string, passing a regex that matches a consecutive sequence of digits....
🌐
xjavascript
xjavascript.com › blog › regex-using-javascript-to-return-just-numbers
How to Use JavaScript Regex to Extract Numbers from Strings: Return Just Numeric Parts — xjavascript.com
This guide will walk you through exactly how to use JavaScript regex to extract numeric parts—from simple integers to complex decimals, negatives, and formatted numbers—with step-by-step examples and best practices. ... Before diving into number extraction, let’s recap essential regex concepts in JavaScript. A Regular Expression (regex) is a sequence of characters defining a search pattern. In JavaScript, regex is used to match, test, or replace patterns in strings.
🌐
xjavascript
xjavascript.com › blog › how-can-i-extract-a-number-from-a-string-in-javascript
How to Extract a Number from a String in JavaScript: Fixing Regex Issues — xjavascript.com
Use Regex Tools: Test regex patterns with tools like regex101.com to visualize matches and debug. Extracting numbers from strings in JavaScript with regex is powerful but requires careful handling of edge cases. By starting with basic patterns, addressing pitfalls like partial matches and thousand separators, and validating results, you can reliably extract numbers for most use cases.
🌐
sqlpey
sqlpey.com › javascript › javascript-extract-numbers-from-strings
JavaScript Techniques for Extracting Numbers from Strings - …
November 4, 2025 - if (!isNaN(parseInt(char)) && char !== ' ') { digits += char; } } // Returns consolidated digits as a string, or potentially an empty string if none found. return digits; } console.log(extractNumberNoRegex('@1200milion$')); // Output: "1200" (Note: This non-regex approach needs careful refinement ...