JavaScript 正則表示式 - \n



描述

\n 匹配換行符 (\u00A)。

示例

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

<html>
   <head>
      <title>JavaScript RegExp</title>
   </head>
   
   <body>
      <script type = "text/javascript">
		 var str = "ab\nc";
         var pattern = /\n/g;

         var index = str.search(pattern);
         document.write("Test 1 - returned value : " +  index); 

         str = "abc";
         index = str.search(pattern);
         document.write("<br/>Test 2 - returned value : " +  index); 	 		 
      </script>
   </body>
</html>

輸出

Test 1 - returned value : 2
Test 2 - returned value : -1
廣告