位置的特性
对于位置的理解,我们可以理解成空字符''
比如hello字符串等价于如下形式:
javascript
"hello" == "" + "h" + "" + "e" + "" + "l" + "" + "l" + "" + "o" + "";也可以等价于,前面可以有无数个
javascript
"hello" == "" + "" + "hello";因此把/^hello$/写成/^^hello$$$/是绝对没有问题的
javascript
var result = /^^hello$$$/.test("hello");
console.log(result);
// => true甚至可以写成更复杂的
javascript
var result = /(?=he)^^he(?=\w)llo$\b\b$/.test("hello");
console.log(result);
// => true也就是字符之间的位置,可以写成多个
把位置理解为空字符,是对位置非常有效的理解方式