- GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
- grep (GNU grep) 2.20
Can someone explain this puzzle? I'm getting false matches with grep/egrep.
echo "somestringthing" | egrep '\bstring*' (no output as expected) echo "somestringthing" | egrep '\bsomestring*' somestringthing echo "somestringthing" | egrep '\bsomestringthingy*' somestringthing echo "somestringthing" | egrep '\bsomestringthing1*' somestringthing echo "somestringthing" | egrep '\bsomestringthingX*' somestringthing
That last three should NOT match because of the single char before the wildcard. Experimenting, I've found that any string will match as if the single character before the wildcard did not exist.
'\b' is a word boundary, FYI.
So am I missing something here, or is this a bug in grep? (Talk about hair-pulling madness trying to debug code you think is working properly.)
*in a regexp means zero-or-more. so
y*means zero-or-more y characters. use a
y\+in BRE) if you mean "one-or-more y characters". or use
.*if you mean "followed by zero-or-more of any other characters"
grep -E, not
egrep. egrep is deprecated
grep -E '\bstring*'is functionally identical to
grep -E '\bstrin'.