Previous Topic: Email Address and URL VariablesNext Topic: Punctuation Variables


Repeat Expressions

To match against repeated words or subexpressions, use square brackets [] after a word. This syntax has the following format:

[*]

Matches any number of times, including zero.

Example: The expression a b[*] c matches both a b b c and a c.

[+]

Matches one or more times.

Example: The expression a b[+] c matches a b b c, but not a c.

[?]

Matches zero or once. That is, the repetition is optional.

Example: The expression a b[?] c matches a b c and a c, but not a b b c.

[N]

Matches N times, where N is a number.

Example: a b[2] c matches a b b c, but not a b b b c.

[N, ]

Matches at least N times.

Example: a b[2,] c matches a b b c, but not a b c.

[,N]

Matches a maximum of N times.

Example: a b[,2] c matches a b b c, but not a b b b c.

[N,Z]

Matches from N to Z times.

Example: a b[1,3] c permits b to be repeated between one and three times. So this expression matches a b b c but not a b b b b c.

Greedy matching

By default, search text matching is ‘non-greedy’. That is, the search stops as soon as it finds a match. For example, if the expression a[+] is matched against a a a a b it returns a. The trigger fires as soon as it detects the first ‘a’.

However, you can make a search ‘greedy’ so that it returns all matching occurrences. For greedy matching, the syntax has the following format:

[+g]

Continues to match one or more times.

Example: When {many}[+g] is matched against many many times, it returns many many.

Example: When b a[+g] is matched against b a a a a, it returns b a a a a

[*g]

Continues to match any number of times, including zero.

Example: When b a[*g] is matched against b a a a a, it returns b a a a a

[?g]

Matches zero or once.

Example: When b a[?g] is matched against b a a a a, it returns b a

[M,g]

Continues to match at least M times.

Example: When b a[2,g] is matched against b a a a a, it returns b a a a a

[ ,Mg]

Matches a maximum of M times.

Example: When b a[ ,3g] is matched against b a a a a, it returns b a a a

[M,Ng]

Matches from M to N times.

Example: When b a[2,4g] is matched against b a a a a, it returns b a a a a