\d
,注意是小写的d
。这等同于元字符[0-9]
,它查找 0 到 9 之间任意数字的单个字符。
\d
来计算电影标题中有多少个数字。书面数字("six" 而不是 6)不计算在内。
'9'
中匹配到 1 个数字。"
testString: assert("9".match(numRegex).length == 1);
- text: "你的正则表达式应该在'Catch 22'
中匹配到 2 个数字。"
testString: assert("Catch 22".match(numRegex).length == 2);
- text: "你的正则表达式应该在'101 Dalmatians'
中匹配到 3 个数字。"
testString: assert("101 Dalmatians".match(numRegex).length == 3);
- text: "你的正则表达式在'One, Two, Three'
中应该匹配不到数字。"
testString: assert("One, Two, Three".match(numRegex) == null);
- text: "你的正则表达式应该在'21 Jump Street'
中匹配到 2 个数字。"
testString: assert("21 Jump Street".match(numRegex).length == 2);
- text: '你的正则表达式应该在"2001: A Space Odyssey"
中匹配到 4 个数字。'
testString: 'assert("2001: A Space Odyssey".match(numRegex).length == 4);'
```