javascript - Regular matching of numbers after a specific statement in a string
迷茫
迷茫 2017-07-05 11:01:37
0
3
1039
var str = "总价为:1400.00元,单价为:200元"

How to use regular expressions or other methods to obtain the two fields 1400.00 and 200 and correspond to the total price and unit price?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
学霸
var str = "总价为:1400.00元,单价为:200元"
var matchResult = /总价为:([\d.]+?)元,单价为:([\d.]+?)元/.exec(str)
if (matchResult) {
  let total = Number(matchResult[1])
  let unit = Number(matchResult[2])
  console.log(total, unit)
}
扔个三星炸死你

I think you can search it.

習慣沉默

var pattern=/d+.d+/g;
var matchs=str.match(pattern);
console.log(matchs);

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!