1

How to format a regular expression In JavaScript :

http://localhost:3000/sales?&tp=Home+Stay&am=Pool&pl=1620&pt=Flash+Sale&st=5

I want to get &pl= and all the digits after &pl=. So the result would be &pl=1620 in this case. Please help how to perform this?? Your help means a lot for me.

Gopal S Rathore
  • 9,885
  • 3
  • 30
  • 38

2 Answers2

0

This script will do the trick:

var regex = /&pl=\d*/;
var match = regex.exec(yourtext)[0];
Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
0

Following regex should do it

/&pl=\d*/.exec('http://localhost:3000/sales?&tp=Home+Stay&am=Pool&pl=1620&pt=Flash+Sale&st=5')[0]

Demo: Fiddel

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531