\w
字母数字[A-Za-z0-9_]
。您可能想要搜索的自然模式与字母数字相反。您可以使用\W
搜索\w
的反面。注意,相反的模式使用大写字母。此快捷方式与[^A-Za-z0-9_]
。 让shortHand = / \ W /;
让数字=“42%”;
let sentence =“Coding!”;
numbers.match(简写); //返回[“%”]
sentence.match(简写); //返回[“!”]
\W
来计算各种引号和字符串中的非字母数字字符数。 "The five boxing wizards jump quickly."
找到6个非字母数字字符"The five boxing wizards jump quickly."
。
testString: 'assert("The five boxing wizards jump quickly.".match(nonAlphabetRegex).length == 6, "Your regex should find 6 non-alphanumeric characters in "The five boxing wizards jump quickly."
.");'
- text: 你的正则表达式应该使用速记字符。
testString: 'assert(/\\W/.test(nonAlphabetRegex.source), "Your regex should use the shorthand character to match characters which are non-alphanumeric.");'
- text: 你的正则表达式应该在"Pack my box with five dozen liquor jugs."
找到8个非字母数字字符"Pack my box with five dozen liquor jugs."
testString: 'assert("Pack my box with five dozen liquor jugs.".match(nonAlphabetRegex).length == 8, "Your regex should find 8 non-alphanumeric characters in "Pack my box with five dozen liquor jugs."
");'
- text: 你的正则表达式应该在"How vexingly quick daft zebras jump!"
找到6个非字母数字字符"How vexingly quick daft zebras jump!"
testString: 'assert("How vexingly quick daft zebras jump!".match(nonAlphabetRegex).length == 6, "Your regex should find 6 non-alphanumeric characters in "How vexingly quick daft zebras jump!"
");'
- text: 你的正则表达式应该在"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."
找到12个非字母数字字符"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."
testString: 'assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(nonAlphabetRegex).length == 12, "Your regex should find 12 non-alphanumeric characters in "123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."
");'
```