Questão de Linux Administration #019e3987
What does the symbol within regular expressions represent?
Match the preceding qualifier one or more times.
Match the preceding qualifier zero or more times.
Match the preceding qualifier zero or one times.
Match a literal character.
Explicação Oficial / Explicações da Comunidade
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+cwould require at least oneb. - "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\*.