Regex Character Classes
Brackets, ranges, and negation for precise character sets.
- character class
- regex range
- negated class
- unicode regex
- match chinese
Regex Character Classes
Brackets, ranges, and negation for precise character sets.
Commands
| Command | What it does |
|---|---|
[aeiou] | Any one vowel |
[a-zA-Z] | Any ASCII letter |
[^0-9] | Any non-digit |
[\w.-]+ | Word chars, dots, hyphens |
\p{L} | Any unicode letter (u flag) |
Example
^[A-Za-z][A-Za-z0-9_.-]{2,31}$ # username rule
FAQ
Where does a hyphen go in brackets?
First or last position keeps it literal; in the middle it defines a range.
How do I match CJK text?
Use the Han unicode range or Script=Han property with the u flag in JavaScript.
Soalan Lazim
Where does a hyphen go in brackets?
First or last position keeps it literal; in the middle it defines a range.
How do I match CJK text?
Use the Han unicode range or Script=Han property with the u flag in JavaScript.