Reputation: 23
I'm new to regular expressions and I'm trying to implement some code which gets the webhook ID and token from a Discord link. Example:
https://discordapp.com/api/webhooks/ID/TOKEN/
I've managed to get this so far: (I'm not sure if it's correct)
https:\/\/.+\/api\/webhooks\/
The regex is supposed to find the ID and TOKEN only.
I'm new to this so any help and advice would be appreciated.
Upvotes: 2
Views: 2829
Reputation: 1
Updated regex:
^.*(discord|discordapp).com\/api\/webhooks\/([\d]+)\/([a-zA-Z0-9_.-]*)$
Upvotes: 0
Reputation: 1833
let res = "https://discordapp.com/api/webhooks/ID123/TOKEN123/".match(/discordapp.com\/api\/webhooks\/([^\/]+)\/([^\/]+)/);
console.log(res[1]) // ID
console.log(res[2]) // TOKEN
Upvotes: 5