7.3. The "*" and Friends

In order to repeat a character more than one time, several repetition patterns can be used. The asterisk (*) can be used to indicate that the character should repeat zero or more times. The plus sign (+) can be used to indicate that the character should repeat one or more times. As for the question mark (?) it indicates an appearance of zero or one time.

The following pattern /ab*c/ matches "a", followed by as many times of b as we like (including zero), and then c. The pattern /you k?now/ matches both "you know" and "you now". The pattern /hello +world/ matches the word "hello" followed by the word "world". (with some whitespace in between).


Written by Shlomi Fish