Repeaters

Repeaters are special characters (or metacharacters) indicating how many times the previous character has to be repeated to get a match. When put after a group, it indicates how many times the group has to be repeated. We didn’t cover groups yet, but we ‘ll do that soon.

Repeater
A repeater indicates how many times the previous character has to be repeated. When put just after a group, it indicates how many times the group has to be repeated.

 
The following figure illustrates the use of the repeater +:

Let us take a look at all the available repeaters:

Repeaters
* Zero or more times.
+ One or more times.
? Zero or one times.
{m,n} At least m and at most n times.

Repeaters are greedy. The matching engine goes first as far as it can, repeating the specified character or group. If no complete match can be found thereafter, it will then progressively go back and retry the rest of the regex again and again. Take an example. While you might think this would happen:

What happens is actually this: