character sets
para especificar um grupo de caracteres a serem correspondidos, mas isso é muita digitação quando você precisa corresponder a um grande intervalo de caracteres (por exemplo, todas as letras do alfabeto). Felizmente, há um recurso embutido que torna isso simples e curto. Dentro de um character set
, você pode definir um intervalo de caracteres para corresponder usando um caractere de hyphen
: -
. Por exemplo, para corresponder letras minúsculas de a
até e
você usaria [ae]
. deixe catStr = "cat";
deixe batStr = "bat";
let matStr = "mat";
deixe bgRegex = / [ae] em /;
catStr.match (bgRegex); // Retorna ["gato"]
batStr.match (bgRegex); // Retorna ["bat"]
matStr.match (bgRegex); // Retorna nulo
quoteSample
. Nota alphabetRegex
deve corresponder a 35 itens.
testString: 'assert(result.length == 35, "Your regex alphabetRegex
should match 35 items.");'
- text: Seu regex alphabetRegex
deve usar o sinalizador global.
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex alphabetRegex
should use the global flag.");'
- text: Seu regex alphabetRegex
deve usar o sinalizador insensível a maiúsculas e minúsculas.
testString: 'assert(alphabetRegex.flags.match(/i/).length == 1, "Your regex alphabetRegex
should use the case insensitive flag.");'
```