/Hello/
搜索到了字符串"Hello"
。那个正则表达式在字符串中搜寻"Hello"
的文字匹配。下面是另一个在字符串中搜寻"Kevin"
的示例:
```js
let testStr = "Hello, my name is Kevin.";
let testRegex = /Kevin/;
testRegex.test(testStr);
// Returns true
```
任何其他形式的"Kevin"
都不会被匹配。例如,正则表达式/Kevin/
不会匹配"kevin"
或者"KEVIN"
。
```js
let wrongRegex = /kevin/;
wrongRegex.test(testStr);
// Returns false
```
后续的挑战将为你展示如何匹配其他形式的字符串。
waldoRegex
,在字符串waldoIsHiding
中匹配到文本"Waldo"
。
waldoRegex
应该匹配到'Waldo'
。"
testString: assert(waldoRegex.test(waldoIsHiding));
- text: 你的正则表达式waldoRegex
不应该搜寻其他的任何内容。
testString: assert(!waldoRegex.test('Somewhere is hiding in this text.'));
- text: 你应该使用你的正则表达式对字符串执行文字匹配。
testString: assert(!/\/.*\/i/.test(code));
```