能否从这个中获取以下3组信息:
- 美国
- 专利
- 6570557(不带逗号)
目前我已经得到:
(US)(\s{1}Patent\s{1})(\d{1},\d{3},\d{3})
我试图去掉逗号,但是如果使用(?!,)
就会导致整个数字被删除。
能否从这个中获取以下3组信息:
目前我已经得到:
(US)(\s{1}Patent\s{1})(\d{1},\d{3},\d{3})
我试图去掉逗号,但是如果使用(?!,)
就会导致整个数字被删除。
尝试使用:
var input = 'US Patent 6,570,557',
matches = input.match(/^(\w+) (\w+) ([\d,]+)/),
code = matches[1],
name = matches[2],
numb = matches[3].replace(/,/g,'');
不需要使用正则表达式,你可以通过两个简单的函数来实现:
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
这也应该会更快。
只需添加更多的组,如下所示:
(US)(\s{1}Patent\s{1})(\d{1}),(\d{3}),(\d{3})
然后将最后3组连接起来
/(US)(\sPatent\s)([\d,]*)/
懒惰胜利! - kojiro