前端js我想提取金额里面的数字比如100万我想提取前面的数字100
可以使用正则表达式来提取金额中的数字,例如:
const amount = '100万';
const regex = /(\d+)/;
const match = amount.match(regex);
const number = match[1];
console.log(number); // 输出 100
上述代码中,使用正则表达式 (\d+) 匹配字符串中的数字,然后通过 match 方法获取匹配结果,再从匹配结果中取出第一个分组中的数字。
原文地址: https://www.cveoy.top/t/topic/hqvm 著作权归作者所有。请勿转载和采集!