Insert a Regex Token to Repeat Another Token

The Insert Token button on the Create panel makes it easy to insert regular expression tokens to repeat other tokens in your regular expression. Repeating tokens is done with "quantifiers". See the Insert Token help topic for more details on how to build up a regular expression via this menu.

A quantifier repeats the preceding regular expression token or group. If you specify a nonzero minimum amount, the regular expression will fail to match if the token can't be repeated that many times. If you specify a maximum amount rather than ticking the "unlimited" checkbox, the token will be repeated at most that many times. Note that it doesn't matter if it could have been repeated more times. The remainder of the subject text is simply ignored, or left for the remainder of the regular expression to match.

If the minimum and maximum are equal, then the regex engine will simply try to repeat the token that many times. If the maximum amount is greater than the minimum, or unlimited, then the repetition style that you choose comes into play.

The "greedy" mode is supported by all regular expression flavors. This mode first tries to match the maximum allowed, and then reduces the repetition one step at a time up to the minimum as long as the remainder of the regular expression fails to match.

The "lazy" mode is supported by many applications. It's essentially the opposite of greedy. It matches the minimum required, and then expands the repetition step by step as long as the remainder of the regex fails to match.

The "possessive" mode is a relatively new feature only supported by a few regular expression flavors. It will try to match as many times as it can, up to the maximum, and then stop. If the remainder of the regex fails to match, it will not reduce the repetition.

If you have the subject string aaaa and you want to repeat the regex token a between 1 and unlimited times, the greedy quantifier a+ matches aaaa, the lazy quantifier a+? matches a and the possessive quantifier a++ also matches aaaa.

If we put a dot at the end of the regex indicating that after our 1 to unlimited a characters we one to match one more character, regardless of what it is, then the greedy quantifier a+. still matches aaaa (three times a followed by any one character). The lazy quantifier a?. matches aa (one a followed by any one character). The possessive quantifiera++., however, fails to match. First a++ matches all four aaaa characters. Then there's nothing left for the dot to match. Unlike the greedy quantifier, the possessive one doesn't give back.

It's important to understand these mechanics of repeating a token and giving back. This is called backtracking. See the regular expressions tutorial for a more in-depth explanation.

Insert quantifiers