English 中文(简体)
JavaScript RegExp Tutorial

Selected Reading

JavaScript RegExp - g
  • 时间:2024-09-17

JavaScript RegExp - g


Previous Page Next Page  

Description

g performs a global match that is, find all matches rather than stopping after the first match.

Example

Following example shows usage of RegExp expression.


<html>
   <head>
      <title>JavaScript RegExp</title>
   </head>
   
   <body>
      <script type = "text/javascript">
         var str = "abcabcabc";
         var pattern = /abc/g;

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

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

Output


Test 1 - returned value : abc,abc,abc
Test 2 - returned value : abc
Advertisements