Sat*_*hya 1 html javascript css
我有一个字符串,如下所示
var str = "This product price is £15.00 and old price is £19.00";
Run Code Online (Sandbox Code Playgroud)
我需要得到以"£"开头的词; 结果应为"£15.00""£19.00"我如何在Javascript中执行此操作?
使用String#match方法
var str = "This product price is £15.00 and old price is £19.00";
// if `£` follows non-digit also then use
console.log(str.match(/£\S+/g));
// if `£` follows only number with fraction
console.log(str.match(/£(\d+(\.\d+)?)/g));Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
569 次 |
| 最近记录: |