0

我正在尝试使用 RegExp 匹配这个部分 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

理想情况下,我需要匹配 'u' 值并将其转换为正确的 url(即,将 %3A 替换为:,将 %2F 替换为 /),但我很乐意匹配整个表达式。

我尝试了许多正则表达式组合,但没有任何成功。

4

2 回答 2

0

尝试 :

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]);
于 2012-08-21T15:06:51.823 回答
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=([^&]+)/);

这是一个jsFiddle

于 2012-08-21T17:10:35.877 回答