Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 镀铬手柄是否正确匹配?_Javascript_Regex_Match - Fatal编程技术网

Javascript 镀铬手柄是否正确匹配?

Javascript 镀铬手柄是否正确匹配?,javascript,regex,match,Javascript,Regex,Match,我的理解是,对于JavaScript中基于大小写不敏感的正则表达式的匹配,可以使用以下两种方法之一:match(/pattern/i)或match(“pattern”,“i”)。不过,我不会让第二个变体在Chrome中工作。(我使用的是铬14.0.835.202)。这是Chrome中的一个bug吗?(还是用户错误?) 在Firefox中,当我运行此代码时,我得到:Hello World,然后是Hello World。在Chrome中,我得到Hello World,未定义 <html>

我的理解是,对于JavaScript中基于大小写不敏感的正则表达式的匹配,可以使用以下两种方法之一:
match(/pattern/i)
match(“pattern”,“i”)
。不过,我不会让第二个变体在Chrome中工作。(我使用的是铬14.0.835.202)。这是Chrome中的一个bug吗?(还是用户错误?)

在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>

函数按钮单击()
{
str=“你好,世界”
警报(str.match(/hello world/i))
警报(str.match(“你好,世界”,“我”))
}

不,这不是一个bug。Firefox允许在
String.match
中使用
flags
参数,但正如Mozilla文档中所指出的(或者更确切地说,正如过去所指出的那样),这是不标准的,应该避免使用。而且,它通常效率较低


如果需要此功能,请改用
新RegExp

不,这不是错误。Firefox允许在
String.match
中使用
flags
参数,但正如Mozilla文档中所指出的(或者更确切地说,正如过去所指出的那样),这是不标准的,应该避免使用。而且,它通常效率较低


如果需要此功能,请改用
new RegExp

并且,的第145页没有提到
.match()
的第二个参数,谢谢。这正是我需要的。而且,的第145页并没有提到
.match()
的第二个参数,谢谢。正是我需要的。