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