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