\r is not part of standard basic nor extended regular expressions except in
awk, though some
greps support it as an extension like the
grep from ast-open which supports it in all its regexp flavours (with
-P and with the default BRE).
It's part of
perl regular expressions though, as well as PCRE ones, so should be supported by
grep implementations that support a
-P for those.
Most shells these days support the
$'...' form of quotes from ksh93, where
\r is expanded to a carriage return. So with those, you can do:
PCRE allows specifying the type of line delimiter with directives such as
(*CR), but that can't be used in
grep -P even in those where perl-like matching is implemented using PCRE, because
grep works on the contents of one (LF-delimited) line at a time, so the LF is not found in the string that the regexp matches against.
It could be used however in
$ printf '%s\r\n' foo abcd bar | pcregrep -M '(*CRLF)d$' | sed -n l
sed -n l to reveal the the CR as
grep, you could use it with the
-z flag that makes it work on NUL-delimited records instead of lines:
$ printf '%s\r\n' foo abcd bar | grep -oPz '(*CRLF)(?m).*d$' | tr '\0' '\n' | sed -n l
(also enabling the
multiline flag for
$ to match at the end of each line in addition to at the end of the record, and
transliterating the NULs to LF on output for display).