How to find a number in a string using JavaScript? | Regex using javascript to return just numbers

preview_player
Показать описание
When you will need to extract numbers from a string. In this tutorial we show a simple method using a regular expression with the String match method.

Suppose I have a string like - "you can enter maximum 500 choices". I need to extract 500 from the string.

The main problem is the String may vary like "you can enter maximum 12500 choices". So how to get the integer part?

Stack Overflow

Regex using javascript to return just numbers

If I have a string like "something12" or "something102", how would I use a regex in javascript to return just the number parts?

W3school
Рекомендации по теме