Linux Administration
medium

Pregunta de Linux Administration #019e3987

Enunciado de la Pregunta
Linux Administration
#regex
#quantifier
#metacharacter
#grep
#sed
Medio

What does the symbol within regular expressions represent?

A

Match the preceding qualifier one or more times.

B

Match the preceding qualifier zero or more times.

Correcto
C

Match the preceding qualifier zero or one times.

D

Match a literal character.

Explicación Oficial / Explicaciones de la Comunidad

The * symbol in regular expressions is a quantifier that matches the preceding element zero or more times. It is one of the most fundamental metacharacters, allowing flexible pattern matching where the preceding character or group may appear any number of times, including not at all.

How it Works

In regex engines, the * quantifier is applied to the immediately preceding character or group. For example, the pattern ab*c matches ac, abc, abbc, abbbc, and so on. The * makes the b optional but also allows multiple occurrences. This behavior is distinct from other quantifiers: + requires one or more occurrences, and ? allows zero or one.

Why the Correct Value is Right

The correct answer is "Match the preceding qualifier zero or more times." This is the standard definition of the * quantifier in virtually all regex flavors (POSIX, Perl-compatible, etc.). It is used extensively in tools like grep, sed, awk, and programming languages.

Why the Incorrect Values are Wrong

  • "Match the preceding qualifier one or more times" describes the + quantifier, not *. For example, ab+c would require at least one b.
  • "Match the preceding qualifier zero or one times" describes the ? quantifier, which makes the preceding element optional but only allows a single occurrence.
  • "Match a literal character" is incorrect because * is a metacharacter with special meaning; to match a literal asterisk, it must be escaped as \*.