d
的缩写\d
来搜寻数字。也可以使用类似的缩写来搜寻非数字,该缩写使用大写的D
。
查找非数字字符的缩写是\D
。这等同于字符串[^0-9]
,它查找不是 0 - 9 之间数字的单个字符。
\D
来计算电影标题中有多少非数字。
'9'
中应该匹配不到非数字。"
testString: assert("9".match(noNumRegex) == null);
- text: "你的正则表达式应该在'Catch 22'
中匹配到 6 个非数字。"
testString: assert("Catch 22".match(noNumRegex).length == 6);
- text: "你的正则表达式应该在'101 Dalmatians'
中匹配到 11 个非数字。"
testString: assert("101 Dalmatians".match(noNumRegex).length == 11);
- text: "你的正则表达式应该在'One, Two, Three'
中匹配到 15 个非数字。"
testString: assert("One, Two, Three".match(noNumRegex).length == 15);
- text: "你的正则表达式应该在'21 Jump Street'
中匹配到 12 个非数字。"
testString: assert("21 Jump Street".match(noNumRegex).length == 12);
- text: '你的正则表达式应该在"2001: A Space Odyssey"
中匹配到 17 个非数字。'
testString: 'assert("2001: A Space Odyssey".match(noNumRegex).length == 17);'
```