# matches and returns b $ echo "abc" | grep -oP "aK(b)(?=c)" b # no match $ echo "abc" | grep -oP "zK(b)(?=c)" # no match $ echo "abc" | grep -oP "aK(b)(?=d)"