grep capture group

Shell
# matches and returns b
$ echo "abc" | grep -oP "a\K(b)(?=c)" 
b 
# no match
$ echo "abc" | grep -oP "z\K(b)(?=c)"
# no match
$ echo "abc" | grep -oP "a\K(b)(?=d)"
Source

Also in Shell: