I have tested \\v
(vertical white space) for matching \\r\\n
and their combinations, but I found out that \\v
does not match \\r
This doesn't answer the question for alternatives, because \v works perfectly well
\v
matches any character considered vertical whitespace; this includes the platform's carriage return and line feed characters (newline) plus several other characters, all listed in the table below.
You only need to change "#\v+#"
to either
"#\\v+#"
escape the backslashor
'#\v+#'
use single quotesIn both cases, you will get a match for any combination of \r
and \n
.
Update:
Just to make the scope of \v
clear in comparison to \R
, from perlrebackslash
- \R
\R
matches a generic newline; that is, anything considered a linebreak sequence by Unicode. This includes all characters matched by\v
(vertical whitespace), ...