这是否有可能:
美国专利6 570 557
检索三个组,即:
到目前为止我得到了:
(US)(\s{1}Patent\s{1})(\d{1},\d{3},\d{3})我试着用(?!,)去掉逗号,然后我有效地去掉了整个数字。
发布于 2013-01-22 13:47:37
试着:
var input = 'US Patent 6,570,557',
matches = input.match(/^(\w+) (\w+) ([\d,]+)/),
code = matches[1],
name = matches[2],
numb = matches[3].replace(/,/g,'');发布于 2013-01-22 13:57:05
与使用regex不同,您可以使用两个简单的函数来完成它:
var str = "US Patent 6,570,557"; // Your input
var array = str.split(" "); // Separating each word
array[2] = array[2].replace(",", ""); // Removing commas
return array; // The output这也应该更快。
发布于 2013-01-22 13:47:19
匹配时不能忽略逗号,除非将数字匹配为三个独立部分,然后将它们连接在一起。
最好用String.replace从匹配结果中去掉分隔符。
https://stackoverflow.com/questions/14459998
复制相似问题