js-regex-mini-book icon indicating copy to clipboard operation
js-regex-mini-book copied to clipboard

关于2.3位置的特性有个问题

Open includenaneve opened this issue 5 years ago • 1 comments

"hello" == "" + "" + "hello" 根据第二章锚点图我可以理解“位置”的特征。但是这里hello前面为什么可以有两个“位置”?而且/^hello$/ 写成 /^^hello$$$/ 这两个正则是怎么等价的

includenaneve avatar Sep 23 '19 17:09 includenaneve

刚才在chrome调试了一下。oh, 我懂了。因为这里是让我们把理解成 “”(空字符)。所以多个空字符相加也是空字符。而 “^” 和 “$” 也是表示一个 “位置”,因此也可以类比成 “”(空字符)。所以我在加了n个“^”在hello前面匹配的结果也是true。

includenaneve avatar Sep 23 '19 17:09 includenaneve