Copyright © tutorialspoint.com

Javascript String - match() Method

previous next

Advertisements


Description:

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

Syntax:

string.match( param )

Here is the detail of parameters:

Return Value:

Example:

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

document.write(found ); 

</script>
</body>
</html>

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

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


previous next

Copyright © tutorialspoint.com