character sets
para especificar un grupo de caracteres para hacer coincidir, pero eso es mucho para escribir cuando necesita hacer coincidir una gran variedad de caracteres (por ejemplo, todas las letras del alfabeto). Afortunadamente, hay una característica incorporada que hace que esto sea breve y simple. Dentro de un character set
, puede definir un rango de caracteres para hacer coincidir usando un carácter de hyphen
: -
. Por ejemplo, para que coincida con las letras minúsculas a
medio e
que usaría [ae]
. vamos catStr = "gato";
dejar batStr = "bat";
dejar matStr = "mat";
vamos bgRegex = / [ae] en /;
catStr.match (bgRegex); // Devoluciones ["cat"]
batStr.match (bgRegex); // Devoluciones ["bat"]
matStr.match (bgRegex); // Devoluciones nulas
quoteSample
. Nota alphabetRegex
debe coincidir con 35 elementos.
testString: 'assert(result.length == 35, "Your regex alphabetRegex
should match 35 items.");'
- text: Su regex alphabetRegex
debe usar la bandera global.
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex alphabetRegex
should use the global flag.");'
- text: Su regex alphabetRegex
debe usar la bandera que no distingue entre mayúsculas y minúsculas.
testString: 'assert(alphabetRegex.flags.match(/i/).length == 1, "Your regex alphabetRegex
should use the case insensitive flag.");'
```