url = ‘http://1dwen.cn/index.php/joi...’How to use regular expression to match the value 22 after uid? Can any expert help me?
'http://1dwen.cn/index.php/uid/22/join/team_list?share_text=3&share_pic=12'.match(/http:\/\/1dwen\.cn\/index\.php\/uid\/(\d+)/)[1]
Can I understand that you only need to match the last number
\d+(?=[^\d]*$)
/https?:\/\/(?:[^\/]+\/)+(\d+)/
var url = new URL("http://1dwen.cn/index.php/join/team_list/uid/22?share_text=3&share_pic=12"); var pathname = url.pathname; var reg = /\d+$/gi; var result = pathname.match(reg);
For js or java, you can use methods such as indexOf and subString
var index = 'asdf'.indexOf('s') ;// ---> 1 'asdf'.substring(index); //....
If you are using regular expressions (js version), you can use regular expression grouping:
t = /uid\/(.*)\?/.exec('http://1dwen.cn/index.php/join/team_list/uid/22?share_text=3&share_pic=12'); console.log(t[1]);
Can I understand that you only need to match the last number
For js or java, you can use methods such as indexOf and subString
If you are using regular expressions (js version), you can use regular expression grouping: