[A-Za-z0-9_]
usando \w
. Um padrão natural que você pode querer pesquisar é o oposto de alfanuméricos. Você pode procurar o oposto do \w
com \W
Note que o padrão oposto usa uma letra maiúscula. Este atalho é o mesmo que [^A-Za-z0-9_]
. deixe shortHand = / \ W /;
deixar números = "42%";
vamos sentenciar = "Codificação!";
numbers.match (shortHand); // Retorna ["%"]
sentence.match (shortHand); // Retorna ["!"]
\W
para contar o número de caracteres não alfanuméricos em várias aspas e cadeias de caracteres. "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: Seu regex deve usar o caractere abreviado.
testString: 'assert(/\\W/.test(nonAlphabetRegex.source), "Your regex should use the shorthand character to match characters which are non-alphanumeric.");'
- text: Seu regex deve encontrar 8 caracteres não-alfanuméricos em "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: Seu regex deve encontrar 6 caracteres não-alfanuméricos em "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: Seu regex deve encontrar 12 caracteres não-alfanuméricos em "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."
");'
```