url = ‘http://1dwen.cn/index.php/joi...’
How to use regular expression to match the value 22 after uid? Can any expert help me?
代言2017-06-12 09:32:09
'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]
扔个三星炸死你2017-06-12 09:32:09
Can I understand that you only need to match the last number
\d+(?=[^\d]*$)
大家讲道理2017-06-12 09:32:09
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);
给我你的怀抱2017-06-12 09:32:09
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]);