LX0-103 · Question #198
What does the ? symbol within regular expressions represent?
The correct answer is C. Match the preceding qualifier zero or one times.. In regular expressions, the ? quantifier makes the preceding element optional by matching it exactly zero or one times.
Question
What does the ? symbol within regular expressions represent?
Options
- AMatch the preceding qualifier one or more times.
- BMatch the preceding qualifier zero or more times.
- CMatch the preceding qualifier zero or one times.
- DMatch a literal ? character.
How the community answered
(18 responses)- A6% (1)
- C89% (16)
- D6% (1)
Why each option
In regular expressions, the ? quantifier makes the preceding element optional by matching it exactly zero or one times.
The + quantifier matches the preceding element one or more times, not ?.
The * quantifier matches the preceding element zero or more times, not ?.
The ? quantifier specifies that the preceding element may appear once or not at all, making it optional. For example, colou?r matches both 'color' and 'colour' because the 'u' is optional. This behavior is defined in both POSIX extended regex and Perl-compatible regex standards.
A literal ? character is matched by escaping it as \? in most regex dialects; unescaped ? acts as a quantifier.
Concept tested: regex quantifier ? zero or one times
Source: https://www.gnu.org/software/grep/manual/grep.html#Fundamental-Structure
Topics
Community Discussion
No community discussion yet for this question.