How do I extract only part of a matched string with regex?

This question already has an answer here:

  • What is the difference between RegExp's exec() function and String's match() function? 4 answers
  • How do you access the matched groups in a JavaScript regular expression? 14 answers

  • 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正则表达式不是

    下一篇: 如何只用正则表达式提取匹配的字符串的一部分?