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
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
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!