LFCS · Question #798
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 ? symbol acts as a quantifier, matching the preceding element zero or one time, making it optional.
Question
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
(32 responses)- A3% (1)
- C91% (29)
- D6% (2)
Why each option
In regular expressions, the `?` symbol acts as a quantifier, matching the preceding element zero or one time, making it optional.
Matching the preceding qualifier one or more times is represented by the `+` symbol in regular expressions.
Matching the preceding qualifier zero or more times is represented by the `*` symbol in regular expressions.
The `?` quantifier in regular expressions signifies that the character, group, or class immediately preceding it can occur zero times or one time, essentially making that element optional in the match.
To match a literal `?` character in a regular expression, it must be escaped with a backslash, i.e., `\?`.
Concept tested: Regular expression quantifiers (?)
Source: https://www.gnu.org/software/grep/manual/grep.html#Regular-Expressions
Topics
Community Discussion
No community discussion yet for this question.