- Boolean "or"
- A vertical bar separates alternatives. For example,
gray|grey
can match "gray" or "grey". - Grouping
- Parentheses are used to define the scope and precedence of the operators (among other uses). For example,
gray|grey
andgr(a|e)y
are equivalent patterns which both describe the set of "gray" and "grey". - Quantification
- A quantifier after a token (such as a character) or group specifies how often that preceding element is allowed to occur. The most common quantifiers are the question mark
?
, the asterisk*
(derived from the Kleene star), and the plus sign+
(Kleene cross).
?
The question mark indicates there is zero or one of the preceding element. For example, colou?r
matches both "color" and "colour".*
The asterisk indicates there are zero or more of the preceding element. For example, ab*c
matches "ac", "abc", "abbc", "abbbc", and so on.+
The plus sign indicates that there is one or more of the preceding element. For example, ab+c
matches "abc", "abbc", "abbbc", and so on, but not "ac".
end
No comments:
Post a Comment