返回嵌入在文档字符串中的值数组的javascript正则表达式
因此,我并不真正了解正则表达式的细微差别(甚至是基本的差别),所以我只想问一下,是否有人可以生成一个Javascript正则表达式,它通过以下字符串,执行item/Regex并返回一个[4378382]数组:返回嵌入在文档字符串中的值数组的javascript正则表达式,javascript,regex,Javascript,Regex,因此,我并不真正了解正则表达式的细微差别(甚至是基本的差别),所以我只想问一下,是否有人可以生成一个Javascript正则表达式,它通过以下字符串,执行item/Regex并返回一个[4378382]数组: var tmp_str="here is <a href='/arc/item/4'>item - more item stuff</a> and there are other things <a href='/arc/item/378'>anothe
var tmp_str="here is <a href='/arc/item/4'>item - more item stuff</a> and there are other things <a href='/arc/item/378'>another item - more item stuff</a> and finally <a href='/arc/item/382'>last item - more item stuffvar </a>"
帮我堆叠溢出的窥视,你是我唯一的希望使用
\d
匹配数字:
tmp_str.match(/item\/\d+/g)
// => ["item/4", "item/378", "item/382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.substr(5); })
// => ["4", "378", "382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.match(/\d+/)[0] })
// => ["4", "378", "382"]
使用
\d
匹配数字:
tmp_str.match(/item\/\d+/g)
// => ["item/4", "item/378", "item/382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.substr(5); })
// => ["4", "378", "382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.match(/\d+/)[0] })
// => ["4", "378", "382"]
使用
\d
匹配数字:
tmp_str.match(/item\/\d+/g)
// => ["item/4", "item/378", "item/382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.substr(5); })
// => ["4", "378", "382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.match(/\d+/)[0] })
// => ["4", "378", "382"]
使用
\d
匹配数字:
tmp_str.match(/item\/\d+/g)
// => ["item/4", "item/378", "item/382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.substr(5); })
// => ["4", "378", "382"]
tmp_str.match(/item\/\d+/g).map(function(m) { return m.match(/\d+/)[0] })
// => ["4", "378", "382"]
太棒了,太多了。要等几天才能接受。我的理智是安全的。@falsetru,是否可以对
项节使用非捕获组(?:)。@Ergec,当然,这是可能的。但我没有使用任何反向参考。所以这不会有任何区别。@falsetru,如果可能的话,你能不能也举一个例子,只是为了将来reference@Ergec,tmp\u str.match(/(?:item\/)\d+/g).map(函数(m){返回m.match(/\d+/)[0]})
?太棒了,太棒了。要等几天才能接受。我的理智是安全的。@falsetru,是否可以对项节使用非捕获组(?:)。@Ergec,当然,这是可能的。但我没有使用任何反向参考。所以这不会有任何区别。@falsetru,如果可能的话,你能不能也举一个例子,只是为了将来reference@Ergec,tmp\u str.match(/(?:item\/)\d+/g).map(函数(m){返回m.match(/\d+/)[0]})
?太棒了,太棒了。要等几天才能接受。我的理智是安全的。@falsetru,是否可以对项节使用非捕获组(?:)。@Ergec,当然,这是可能的。但我没有使用任何反向参考。所以这不会有任何区别。@falsetru,如果可能的话,你能不能也举一个例子,只是为了将来reference@Ergec,tmp\u str.match(/(?:item\/)\d+/g).map(函数(m){返回m.match(/\d+/)[0]})
?太棒了,太棒了。要等几天才能接受。我的理智是安全的。@falsetru,是否可以对项节使用非捕获组(?:)。@Ergec,当然,这是可能的。但我没有使用任何反向参考。所以这不会有任何区别。@falsetru,如果可能的话,你能不能也举一个例子,只是为了将来reference@Ergec,tmp_str.match(/(?:item\/)\d+/g).map(函数(m){return m.match(/\d+/)[0]})
??