Scope class
When using regular expressions, many times, we would like to match all the letters of A~Z, many people think that we can use the character class [abcdefg...z] , but this method needs to enter all the letters that need to be matched. So, is there a way to do something simple?
Fortunately, regular expressions provide scope classes, which let us use [a-z] to concatenate two characters representing any character from A to Z.
Basic usage
let text = ‘a1b2d3x4z5‘let reg = /[a-z]/gtext.replace(reg, ‘Q‘) // Q1Q2Q3Q4Q5
Tips: It is worth noting that the range class is a closed interval, that is: [a-z] contains A and Z
Ligatures of the Range class
There is a small trick to using the scope class: [] inside a class you can ligatures, for example:[a-zA-Z]
let text = ‘a1B2d3X4Z5‘let reg = /[a-zA-Z]/gtext.replace(reg, ‘Q‘) // Q1Q2Q3Q4Q5
JS Regular expressions from entry to the ground (3)--scope class