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.