0

I was wondering how could I do to separate what triggered the RegExp. What I want to do is get the URL part so I can check if that URL is valid. I've tried several things, but none of them gave a good result. Thank you in advance.

Examples: Valid URL: google.com, invalid url: u9fwhuwh9gi8h9hgwgwvns.com

var re = new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?");
if(re.test(message.content)) {
    urlExists(<Insert Valid URL Here>, function(err, exists) {
        if (exists == true) {
            console.log("Valid URL found");
        }
    });
}
Itsmoloco
  • 31
  • 1
  • 9
  • can you provide an example of a valid url ? – AlexB Mar 04 '18 at 18:13
  • @AlexB Valid URL: google.com, invalid url: u9fwhuwh9gi8h9hgwgwvns.com – Itsmoloco Mar 04 '18 at 18:19
  • To answer the question, use [`exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) on the regex. That will give you an object containing the matches. As far as I can tell, that's what you mean by "triggered". – Heretic Monkey Mar 04 '18 at 21:13

0 Answers0