Negative Character Set
Learn about the anti of the character set to create a more precise RegEx.
Character range
Recall the RegEx you wrote in the previous problem /98[12][0123456789]/g
. Consider the case when you need to match huge integers or alphabets. Writing all the alphabets one by one in a character set would be very tedious. As a solution, another unique character, the hyphen"-"
, is used to express the range. Instead of writing digits or alphabets one by one, you can use this range of characters.
A character range represents the range of characters from one start to end.
- A-Z represents characters from uppercase A to uppercase Z.
- a-z represents characters from lowercase a to lowercase z.
- 0-9 represents numbers from 0 to 9.
You can use this range character inside the character set as well. And that is the reason why you should escape the hyphen "-"
inside the character set.
To write the above-mentioned RegEx more concisely, use the range character. And the RegEx will become /98[12][0-9]/g
...