Consider this text file:
TEST FILE : test #No match
#No match
Run grep "1133*" on this file #Match
#No match
This line contains the number 113. #Match
This line contains the number 13. #No match
This line contains the number 133. #No match
This line contains the number 1133. #Match
This line contains the number 113312. #Match
This line contains the number 1112. #No match
This line contains the number 113312312. #Match
This line contains no numbers at all. #No match
How does the grep command evaluate the 1133* regular expression?
echo "Consider this text file:
TEST FILE : test #No match
#No match
Run grep \"1133*\" on this file #Match
#No match
This line contains the number 113. #Match
This line contains the number 13. #No match
This line contains the number 133. #No match
This line contains the number 1133. #Match
This line contains the number 113312. #Match
This line contains the number 1112. #No match
This line contains the number 113312312. #Match
This line contains no numbers at all. #No match" | grep "1133*"
Outputs:
Run grep "1133*" on this file #Match
This line contains the number 113. #Match
This line contains the number 1133. #Match
This line contains the number 113312. #Match
This line contains the number 113312312. #Match
Why is the line containing 113 a positive?
Is the regular expression 1133* meant to mean anything else than
find all lines that contain the word 1133+anything else?
This example was found on the tldp regexp documentation page.
You’re thinking of a shell wildcard, where
*matches anything. In regular expressions, a*is a quantifier that means “zero or more” of whatever immediately precedes it, which in this case is3.So your expression means
113followed by zero or more3s.