Scenario:
const texto = 'ABC [abc] a-c 1234';
console.log(texto.match(/[A-z]/g))
- Because the set of
A(maiúsculo)
toz(minusculo)
, that is,/[A-z]/g
returned me[
and]
? - The result should not be:
[A, B, C, a, b, c, a, c]
?
const texto = 'ABC [abc] a-c 1234';
console.log(texto.match(/[A-z]/g))
A(maiúsculo)
to z(minusculo)
, that is,
/[A-z]/g
returned me [
and ]
? [A, B, C, a, b, c, a, c]
? [A-z]
will match ASCII characters in sequence from A
to z
. If you look at the ASCII table below you will find that there are several other characters between A
and z
( including the brackets []
that you do not want).
Sinceyouwanttomatchonlyuppercaseandlowercaseletters,fromA
toZ
andfroma
toz
,thecorrectwouldbe[a-zA-Z]
.
const texto = 'ABC [abc] a-c 1234';
console.log(texto.match(/[a-zA-Z]/g))
The range or ranges follow the table Unicode .
I have defined that my set should be A(maiúsculo) até z(minusculo)
, there are symbols in the middle of that range.
They are: [\] ^ _ '
Look at the Unicode table:
The first 127 characters of the Unicode table are the same as the table ASCII