Extract only two-character lines with one lowercase letter followed by one non-digit.
Use LC_ALL=C.
Which ERE is correct?
A bracket expression beginning with ^ negates its character set. [^[:digit:]] therefore matches one character that is not a digit.
Detailed explanation
^[[:lower:]][^[:digit:]]$Correct. It requires a lowercase letter followed by one non-digit and anchors the whole line.
Correct. It requires a lowercase letter followed by one non-digit and anchors the whole line.
^[[:lower:]][[:digit:]]$Incorrect. The second character is required to be a digit, the opposite of the requirement.
Incorrect. The second character is required to be a digit, the opposite of the requirement.
^[^[:lower:]][[:digit:]]$Incorrect. The first character is required to be non-lowercase and the second a digit.
Incorrect. The first character is required to be non-lowercase and the second a digit.
^[[:lower:]^[:digit:]]$Incorrect. The ^ inside this character class is not in the negating first position and the expression does not mean non-digit.
Incorrect. The ^ inside this character class is not in the negating first position and the expression does not mean non-digit.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' a1 a- Z- ab | LC_ALL=C grep -E '^[[:lower:]][^[:digit:]]$'Expected result
a-
abKey points
- ^ at the start of a bracket expression negates it
- Character classes can be negated
- Anchors constrain the line to two characters
Notes
- Environment: GNU grep 3.x / LC_ALL=C
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.