否定字符集
。
要创建否定字符集
,需要在开始括号后面和不想匹配的字符前面放置插入字符
(即^
)。
例如,/[^aeiou]/gi
匹配所有非元音字符。注意,字符.
、!
、[
、@
、/
和空白字符等也会被匹配,该否定字符集仅排除元音字符。
myRegex
应该匹配 9 项。
testString: assert(result.length == 9);
- text: 你的正则表达式myRegex
应该使用全局标志。
testString: assert(myRegex.flags.match(/g/).length == 1);
- text: 你的正则表达式myRegex
应该使用忽略大小写标志。
testString: assert(myRegex.flags.match(/i/).length == 1);
```