Javascript RegExp教程

JavaScript RegExp [0-9]

说明

[0-9] 匹配从 0 到 9 的任何十进制数字。

示例

以下示例显示了 RegExp 表达式的用法。
<html>
   <head>
      <title>JavaScript RegExp</title>
   </head>
   
   <body>
      <script type = "text/javascript">
         var str = "first";
         var pattern = /[0-9]/g;
         var result = str.match(pattern);
         document.write("Test 1-returned value : " +  result); 
         str = "2nd";
         result = str.match(pattern);
         document.write("<br/>Test 2-returned value : " +  result); 	 		 
      </script>
   </body>
</html>

输出

Test 1-returned value : null
Test 2-returned value : 2 
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4