When writing a regex patter like [a-zA-Z0-9_-]
which have -
in char class,
it is better that put -
at top. [-a-zA-Z0-9_]
If -
is put at last and after a character: [_-]
,
As a parser of regexp pattern, when met -
after _
(a literal character),
it can't be determined as a range operator or a literal character soon.
So parser pended it, and read next ]
(end of char class),
then treat previous -
as a leteral character.
It is not easy behavior.
But if -
is put at top of char class,
parser easily distiguish as a literal character.
Putting -
at top of regexp's char class, is kindness for parser and its efficiency.