prk
prk

Reputation: 3809

Node.JS - How would I do this regex?

Well I have this:

var regex = /convertID\s(\d+)/
var match = regex.exec(message);
if(match != null)
{
//do stuff here
}

That works fine and it recognizes if someone writes "convertID NumbersHere". However I want to have another one under it as well checking if there's a specific link, for example:

var regex = /convertID\shttp://anysitehere dot com/id/[A-Z]
var match = regex.exec(message);
if(match != null)
{
//do stuff here
}

So how would I make it check for an specific site with any letters after /id/?

Upvotes: 0

Views: 291

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

You can use this:

var regex = /convertID\shttp:\/\/thesite.com\/id\/[A-Za-z]+/;

slashes must be escaped since the slash is used to delimit the pattern. You can avoid this creating explicitly an instance of RegExp class:

var regex = new RegExp("convertID\\shttp://thesite.com/id/[A-Za-z]+");

Upvotes: 1

Related Questions