Question 330
An instructor reviews this Linux fundamentals exercise: A learner reads a regular expression ab* and assumes it means any characters after ab, then receives unexpected matches such as a and abbb. Which limitation most directly accounts for the reported behavior?
Explanation
Correct Answer
The technical basis is: In basic regular expressions, the asterisk repeats the immediately preceding expression zero or more times rather than acting as a generic arbitrary suffix. Resolve this through: Construct a pattern using the correct anchors and tokens for the desired match, and distinguish it from shell filename globbing. The expected evidence is: A controlled test illustrates that ab* can match a plus zero or more b characters, while a separate pattern captures the intended full word.
Incorrect Answers
The wc options count different units: newline-terminated lines, whitespace-delimited words and bytes respectively. “Select the appropriate wc count option for the specified measurement rather than treating all numeric outputs as interchangeable” would remedy that alternative situation, but it would not correct the present issue: in basic regular expressions, the asterisk repeats the immediately preceding expression zero or more times rather than acting as a generic arbitrary suffix.
“Use an appropriate regular expression in grep and quote the pattern so the shell does not transform it first” is the supported response when in basic regular expressions, an unescaped dot matches a single character, and bracket expressions can select a defined character set. Here the decisive response is “Construct a pattern using the correct anchors and tokens for the desired match, and distinguish it from shell filename globbing”, so that different intervention does not meet the stated requirement.
Grep filters input by a pattern and prints matching lines, making it suitable for locating occurrences in text files. “Run grep with the intended literal pattern and appropriate input file, then inspect the matching lines in context” applies to that other condition. The reported evidence is a learner reads a regular expression ab* and assumes it means any characters after ab, then receives unexpected matches such as a and abbb; this alternative would address the wrong dependency.