Home > Web Front-end > JS Tutorial > How to extract numbers from string using regular expression

How to extract numbers from string using regular expression

php中世界最好的语言
Release: 2018-03-19 16:25:10
Original
10059 people have browsed it

This time I will bring you regular expressionsHow to extract numbers from strings, regular expressions for extracting numbers from stringsNotes What are they? Here are actual cases. Let’s take a look.

1 var str = '确定人民币¥115.625';2 var pat = /[\d]+[.][\d]+/;3 document.write(str.match(pat));//115.62511
Copy after login

Solve the problem that parseFloat cannot extract the first character in string is a non-digit.

Similarly, parseInt can be used /[\d]+/

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Recommended reading:

Request cross-domain solution CORS

What are the rules for converting JS type values ​​​​to Boolean types

Using Vue instructions

Using JS closures

The above is the detailed content of How to extract numbers from string using regular expression. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template