JavaScript 字符串 string replace 替换函数


JavaScript 字符串 string replace 替换函数

<html>
   <head>
      <title>JavaScript String replace() Method</title>
   </head>
   <body>
      <script type = "text/javascript">
         var re = /(\w+)\s(\w+)/;
         var str = "zara ali";
         var newstr = str.replace(re, "$2, $1");

         document.write(newstr);
      </script>
   </body>
</html>