^
符号来搜寻字符串开头的匹配模式。还有一种方法可以搜寻字符串末尾的匹配模式。
可以使用正则表达式的美元
符号$
来搜寻字符串的结尾。
```js
let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
// Returns false
```
$
在字符串caboose
的末尾匹配"caboose"
。
$
来搜寻'caboose'
。"
testString: assert(lastRegex.source == "caboose$");
- text: 你的正则表达式不应该使用任何标志。
testString: assert(lastRegex.flags == "");
- text: "你应该在字符串'The last car on a train is the caboose'
的末尾匹配'caboose'
。"
testString: assert(lastRegex.test("The last car on a train is the caboose"));
```