Next: , Previous: , Up: Repetition Operators   [Contents][Index]


18.3.4.3 The Match-zero-or-one Operator (? or \?)

If the syntax bit RE_LIMITED_OPS is set, then Regex doesn’t recognize this operator. Otherwise, if the syntax bit RE_BK_PLUS_QM isn’t set, then ‘?’ represents this operator; if it is, then ‘\?’ does.

This operator is similar to the match-zero-or-more operator except that it repeats the preceding regular expression once or not at all; see The Match-zero-or-more Operator (*), to see what it operates on, how some syntax bits affect it, and how Regex backtracks to match it.

For example, supposing that ‘?’ represents the match-zero-or-one operator; then ‘ca?r’ matches both ‘car’ and ‘cr’, but nothing else.