Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回嵌入在文档字符串中的值数组的javascript正则表达式_Javascript_Regex - Fatal编程技术网

返回嵌入在文档字符串中的值数组的javascript正则表达式

返回嵌入在文档字符串中的值数组的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

因此,我并不真正了解正则表达式的细微差别(甚至是基本的差别),所以我只想问一下,是否有人可以生成一个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'>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]})
??