When attempting to match the newline characters r and n using v (vertical white space), one may encounter unexpected results. However, there are several alternatives to achieve this match.
Alternatives:
R (Unicode Newline Sequence):
<code class="php">preg_match('~\R~', $string); // Matches any Unicode newline sequence in ASCII range preg_match('~\R~u', $string); // Matches any Unicode newline sequence</code>
(*ANYCRLF) R:
<code class="php">preg_match('~(*BSR_ANYCRLF)\R~', $string); // Matches only CR, LF, or CRLF</code>
The above is the detailed content of How to Match \\r and \\n Without Using [\\r\\n]?. For more information, please follow other related articles on the PHP Chinese website!