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,701
  • 4
  • 34
  • 66

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
  • 1,031,962
  • 187
  • 1,923
  • 1,875