Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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正则表达式/e*/导致空匹配_Javascript_Regex - Fatal编程技术网

javascript正则表达式/e*/导致空匹配

javascript正则表达式/e*/导致空匹配,javascript,regex,Javascript,Regex,为什么使用javascript正则表达式 /e*/ 无法匹配字符串“hello”的任何部分 我已经尝试了以下方法 "hello".match(/e*/) //return [""] 而/e+/可以匹配 "hello".match(/e+/) //return ["e"] 我是否忽略了任何简单的东西???它匹配,或者你会因此得到null 匹配的字符串开头为零个字符。您的断言是“在字符串中查找一个位置,其中有零个或多个e”:在hello的开头,有零个或多个e,因此我们不需要进

为什么使用javascript正则表达式

/e*/ 
无法匹配字符串“hello”的任何部分

我已经尝试了以下方法

"hello".match(/e*/)     //return [""]
/e+/
可以匹配

"hello".match(/e+/)     //return ["e"]

我是否忽略了任何简单的东西???

它匹配,或者你会因此得到
null

匹配的字符串开头为零个字符。您的断言是“在字符串中查找一个位置,其中有零个或多个
e
”:在
hello
的开头,有零个或多个
e
,因此我们不需要进一步搜索
match
预期返回
[“”]
(匹配的零个字符)


另一方面,
/e+/
需要一个或多个
e
字符;这在字符串的开头是不满足的,但在下一个位置是满足的,您将得到它匹配的
[“e”]
,否则您将得到
null

匹配的字符串开头为零个字符。您的断言是“在字符串中查找一个位置,其中有零个或多个
e
”:在
hello
的开头,有零个或多个
e
,因此我们不需要进一步搜索
match
预期返回
[“”]
(匹配的零个字符)

另一方面,
/e+/
需要一个或多个
e
字符;这在字符串的开头不满足,但在下一个位置满足,您会得到
[“e”]