您好我有这种网址
www.example.com/registration/star/xx223x/xxxx67x/xx
www.example.com/registration/star-mega/x45xx/xxxrfxx/xx
www.example.com/registration/manager/xxx34xx/xx
www.example.com/registration/pro/xxxxx/xxx
我如何使用javascript和RegEx在/ registration /之后和下一个/ into变量之前获取参数? (明星,明星,经理,亲)
答案 0 :(得分:2)
以下正则表达式如何:www\.example\.com\/registration\/([^\/]+)
?见http://regex101.com/r/xS8zZ6
答案 1 :(得分:2)
为了扩展Uri Y的精彩答案,以下是您在JavaScript中使用它的方法:
var url = 'www.example.com/registration/star-mega/x45xx/xxxrfxx/xx';
var result = url.match('\/registration\/([^\/]+)');
alert(result[1]);