- GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
- grep (GNU grep) 2.20
- grep-2.20-3.el7.x86_64
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. soy*
means zero-or-more y characters. use ay+
(ory\+
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
, notegrep
. egrep is deprecatedgrep
's-o
option),grep -E '\bstring*'
is functionally identical togrep -E '\bstrin'
.