010-160 · Question #91
Which operator in a regular expression matches the preceding character either zero or one time?
The correct answer is A. ? In regular expressions, the ? quantifier matches the immediately preceding element zero or one time, making it optional. Other quantifiers have different repetition semantics.
Question
Options
- A?
- B
- C
- D%
- E$
How the community answered
(64 responses)- A89% (57)
- B5% (3)
- C2% (1)
- D3% (2)
- E2% (1)
Why each option
In regular expressions, the `?` quantifier matches the immediately preceding element zero or one time, making it optional. Other quantifiers have different repetition semantics.
The `?` quantifier in POSIX and PCRE regular expressions means the preceding character or group is optional - it matches either zero times or exactly one time. For example, `colou?r` matches both `color` and `colour`.
`*` matches the preceding character zero or more times (unlimited repetitions).
`+` matches the preceding character one or more times (at least one occurrence required).
`%` is not a standard regular expression quantifier.
`$` is an anchor that matches the end of a line, not a quantifier.
Concept tested: Regular expression quantifiers and their meanings
Source: https://www.gnu.org/software/grep/manual/grep.html#The-Backslash-Character-and-Special-Expressions
Topics
Community Discussion
No community discussion yet for this question.