1
'https://twitter.com/pixelhenk/status/891303699204714496'.match(/\/status\/(\d+)/g)

gives me

[ "/status/891303699204714496" ]

How do I get just the number? I thought putting it in parentheses did this, but apparently not.

stackers
  • 2,084
  • 2
  • 28
  • 47

1 Answers1

5

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]);

...or use RegExp#exec instead of String#match.

console.log(/\/status\/(\d+)/g.exec('https://twitter.com/pixelhenk/status/891303699204714496')[1]);
T.J. Crowder
  • 959,406
  • 173
  • 1,780
  • 1,769