character set内的caret符( ^ )来创建[^thingsThatWillNotBeMatched]形式的negated character set 。在character set , caret用于在字符串的开头搜索模式。 让firstString =“Ricky是第一个,可以找到。”;
让firstRegex = / ^ Ricky /;
firstRegex.test(firstString);
//返回true
让notFirst =“你现在找不到Ricky了。”;
firstRegex.test(notFirst);
//返回false
caret只能在字符串rickyAndCal的开头找到"Cal" 。 "Cal" 。
testString: 'assert(calRegex.source == "^Cal", "Your regex should search for "Cal" with a capital letter.");'
- text: 你的正则表达式不应该使用任何标志。
testString: 'assert(calRegex.flags == "", "Your regex should not use any flags.");'
- text: 你的正则表达式应该匹配字符串开头的"Cal" 。
testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match "Cal" at the beginning of the string.");'
- text: 您的正则表达式不应与字符串中间的"Cal"匹配。
testString: 'assert(!calRegex.test("Ricky and Cal both like racing."), "Your regex should not match "Cal" in the middle of a string.");'
```