【发布时间】:2011-07-12 21:03:07
【问题描述】:
我在一个 html 文件中有一个 JavaScript 函数:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function redirect() {
var queryString = location.search.replace(/^?commonHelpLocation=/, '');
alert(queryString);
window.location = queryString;
}
</script>
</head>
<body onload="redirect();"></body>
</html>
我所在的网址是:
http://somesuperlongstring.mydomain.com/somedirectory/index.html?commonHelpLocation=http://someothersuperlongstring.somedomain.com/help/index.html
因此,location.search 返回:http://someothersuperlongstring.somedomain.com/help/index.html
但该函数也返回相同的字符串,然而,正则表达式应该只返回?commonHelpLocation=http://someothersuperlongstring.somedomain.com/help/index.html
我的正则表达式有问题吗?
【问题讨论】:
标签: javascript html regex