nerdexam
CompTIA

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.

GNU and Unix Commands

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)
  • A
    6% (1)
  • C
    89% (16)
  • D
    6% (1)

Why each option

In regular expressions, the ? quantifier makes the preceding element optional by matching it exactly zero or one times.

AMatch the preceding qualifier one or more times.

The + quantifier matches the preceding element one or more times, not ?.

BMatch the preceding qualifier zero or more times.

The * quantifier matches the preceding element zero or more times, not ?.

CMatch the preceding qualifier zero or one times.Correct

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.

DMatch a literal ? character.

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

#regular expressions#regex quantifiers#pattern matching

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice