yolo
yolo

Reputation: 2805

JavaScript: Regex match this string

I need to check using regex that a string matches this format:

http://site.com/users/1

e.g. a matching string is http://stackoverflow.com/users/587532 and http://stackoverflow.com/users/587532/umar should be not matching.

but I don't know the regex code to do this.

Upvotes: 0

Views: 214

Answers (1)

Yoni
Yoni

Reputation: 10321

http://([^/]+)/users/(\d+)

The first capture group gives you the site's name, the second gives you the user number.

If you need to escape the / characters, just use \/:

http:\/\/([^\/]+)\/users\/(\d+)

Upvotes: 2

Related Questions