nerdexam
LPI

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.

The Power of the Command Line

Question

Which operator in a regular expression matches the preceding character either zero or one time?

Options

  • A?
  • B
  • C
  • D%
  • E$

How the community answered

(64 responses)
  • A
    89% (57)
  • B
    5% (3)
  • C
    2% (1)
  • D
    3% (2)
  • E
    2% (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.

A?Correct

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`.

B*

`*` matches the preceding character zero or more times (unlimited repetitions).

C+

`+` matches the preceding character one or more times (at least one occurrence required).

D%

`%` is not a standard regular expression quantifier.

E$

`$` 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

#regular expressions#regex quantifiers#pattern matching#grep

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice