-2

Hi i have this kind of URLs

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

How can i using javascript and RegEx get the parameter after /registration/ and before the next / into variable? (star, star-mega, manager, pro)

Ilya Libin
  • 1,576
  • 2
  • 17
  • 39

2 Answers2

2

How about the following regex: www\.example\.com\/registration\/([^\/]+)? see http://regex101.com/r/xS8zZ6

Uri Y
  • 840
  • 5
  • 13
2

To expand on the awesome answer by Uri Y, here is how you use it in JavaScript:

var url = 'www.example.com/registration/star-mega/x45xx/xxxrfxx/xx';
var result = url.match('\/registration\/([^\/]+)');
alert(result[1]);

JSFiddle Here.

Jamie Dunstan
  • 3,725
  • 2
  • 24
  • 38