How do I extract only part of a matched string with regex?
This question already has an answer here:
Yes, a capture group does this. You don't see it in your array because you've used String#match
and the g
flag. Either remove the g
flag (and take the second entry from the array, which is the first capture group):
console.log('https://twitter.com/pixelhenk/status/891303699204714496'.match(//status/(d+)/)[1]);
链接地址: http://www.djcxy.com/p/76804.html
上一篇: JS正则表达式不是