JavaScript 正则表达式 - \r


描述

\r 匹配回车符 (\u00D)。

例子

以下示例显示了 RegExp 表达式的用法。


 <script type = "text/javascript">
         var str = "ab\rc";
    var pattern = /\r/g;

    var index = str.search(pattern);
    document.write("测试1 - 返回值 : " +  index); 

    str = "abc";
    index = str.search(pattern);
    document.write("<br/>测试2 - 返回值 : " +  index);          
 </script>

输出

测试1 - 返回值 : 2
测试2 - 返回值 : -1