【发布时间】:2011-11-13 04:27:41
【问题描述】:
我的理解是,可以在 JavaScript 中使用以下两种方法中的任何一种来进行不区分大小写的基于正则表达式的匹配:match(/pattern/i) 或 match("pattern","i")。不过,我没有让第二个变体在 Chrome 中工作。 (我使用的是 Chromium 14.0.835.202)。这是 Chrome 中的错误吗? (或用户错误?)
在 Firefox 中,当我运行此代码时,我得到:Hello World,然后是 Hello World。在 Chrome 中,我得到了未定义的 Hello World。
<html>
<head>
</head>
<body>
<input type="button" id="button" value="Click me!" onclick="buttonClick()" />
</body>
<script language="javascript">
function buttonClick()
{
str="Hello World"
alert(str.match(/hello world/i))
alert(str.match("hello world","i"))
}
</script>
</html>
【问题讨论】:
标签: javascript regex match