Based on this question on SO, I have discovered that:
echo "a']" | grep -E "\a"
Matches OK.
echo "a']" | grep -E "\]"
Matches OK.
But:
echo "a']" | grep -E "\'"
Does not match. I cannot find any documentation to describe how exactly grep -E
handles escaping a single quote. I am using GNU grep 2.16 on Ubuntu 14.04.
NB:
echo "a']" | grep -E "'"
Matches OK, but I am curious as to how grep -E
is interpreting \'
.
Update:
I've just tried this on Cygwin 2.6.1 and grep 2.27 and I can reproduce. Using grep --colour -Eo
perhaps gives a clearer OK/Fail result?
"\'"
does match. I'm not sure what's going on here, ...grep -Eo
: note that when I add the-o
to my grep, nothing's written to stdout (now that's unexpected, AFAIU/not being familiar with that option) yet grep returns with 0 (not 1), which indicates that something was matched.grep -o ""
orgrep -Eo ""
— as steeldriver suggested, an empty pattern patches every line, but matches zero characters.