Tutorials Point

  JavaScript Basics
  JavaScript Objects
  JavaScript Advanced
  JS Useful References
  JS Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Javascript String - match() Method

previous next AddThis Social Bookmark Button



This method is used to retrieve the matches when matching a string against a regular expression.


string.match( param )

Here is the detail of parameters:

  • param : A regular expression object.

Return Value:

  • If the regular expression does not include the g flag, returns the same result as regexp.exec(string).

  • If the regular expression includes the g flag, the method returns an Array containing all matches.


<title>JavaScript String match() Method</title>
<script type="text/javascript">
var str = "For more information, see Chapter";
var re = /(chapter \d+(\.\d)*)/i;
var found = str.match( re );

document.write(found ); 


This returns the array containing Chapter,Chapter,.1:

To understand it in better way you can Try it yourself.

previous next Printer Friendly