Regex Repetition
Some characters in regex have special meaning and are used to specify repetition.
Aterisk (*)
The asterisk *
matches zero or more occurrences of the preceding character.
For example, the regex pattern go*gle
matches ggle
, gogle
, and google
.
Plus (+)
The plus +
matches one or more occurrences of the preceding character.
For example, the regex pattern go+gle
matches gogle
and google
.
Question Mark (?)
The question mark ?
matches zero or one occurrence of the preceding character.
For example, the regex pattern colour
matches color
and colour
.
Curly Braces
{n}
The curly braces {n}
match exactly n
occurrences of the preceding character.
For example, the regex pattern go{2}gle
matches google
.
{n,}
The curly braces {n,}
match n
or more occurrences of the preceding character.
For example, the regex pattern go{2,}gle
matches google
and goooogle
.
{n,m}
The curly braces {n,m}
match between n
and m
occurrences of the preceding character.
For example, the regex pattern go{2,4}gle
matches google
, gooogle
, and goooogle
.