[ ]
–> Brackets. They enclose a list of characters that represent a single character in the expression.
Inside the brackets, one can specify:
-
–> For Ranges
^
–> For negation
.
–> Period. Matches a single character
()
–> Parenthesis. Used to enclose an expression
|
–> Or
Positions:
^
Marks the beggining of the line
$
Marks the end of the line
/<
Marks the beggining of a word
/>
Marks the end of a word
Repetition Operators:
Operator | Description |
---|---|
? | Optional and matched at most once |
* | Zero or more times |
+ | One or more times |
{n} | n times. |
{n,} | n or more times. |
{n,m} | At least n times, but not more than m times |
Examples:
t[a-z]x | matches | tux |
doesn’t match | tUx | |
[^w]in | matches | lin |
doesn’t match | win | |
t.x | matches | tux |
doesn’t match | tuux | |
(t.x|m.x) | matches | tux, mux |
^t.x | matches | tux rules |
doesn’t match | rules tux | |
tu{2}x | matches | tuux |
doesn’t match | tux | |
^.{2,15}$ | Between 2 and 15 characters | |
^[0-9] | Starts with a number | |
[^[:alnum:]] | Contains special characters |