84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
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?
业精于勤,荒于嬉;行成于思,毁于随。
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);
I think you can search it.
var pattern=/d+.d+/g;
var matchs=str.match(pattern);
console.log(matchs);