简体   繁体   中英

JavaScript: Regex match this string

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

http://site.com/users/1

eg 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.

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+)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM