0

I'm trying to match this partial url using RegExp:

/l.php?u=http%3A%2F%2Fwww.transmoto.com.au%2Fpublish%2Fnews%2F14614708%2FBopping%2C-Styke-and-Waters-to-lead-Team-Australia-at-MXoN&h=5AQEDldxs&s=1

Ideally I need to match the 'u' value and convert it to a proper url (i.e replace %3A with : and %2F with /), but I'd be happy just matching the entire expression.

I've tried a number of RegExp combinations but haven't had any success.

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
Jake Jackson
  • 703
  • 5
  • 10

2 Answers2

0

Try :

var match = url.match(/u=([^&]+)/);

/* Alerts http%3A%2F%2Fwww.transmoto.com.au%2Fpublish%2Fnews%2F14614708
   %2FBopping%2C-Styke-and-Waters-to-lead-Team-Australia-at-MXoN */
alert(match[1]);

/* Alerts http://www.transmoto.com.au/publish/news/14614708/Bopping,-Styke
  -and-Waters-to-lead-Team-Australia-at-MXoN */
alert(decodeURIComponent(match[1]);
ttzn
  • 2,543
  • 22
  • 26
0
var url = '/l.php?u=http%3A%2F%2Fwww.transmoto.com.au%2Fpublish%2Fnews%2F14614708%2FBopping%2C-Styke-and-Waters-to-lead-Team-Australia-at-MXoN&h=5AQEDldxs&s=1';
var re = url.match(/\?(?:|.*?&)u=([^&]+)/);

Here's a jsFiddle.

Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145