String match()
match() is the same as RegExp object's exec() method. The match() method accepts a regular-expression string or a RegExp object.
The first item of the returning array is the string that matches the entire pattern. Each other item of the returning array represents capturing groups in the expression.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var text = "loom, room, doom";
var pattern = /.oo/;
var matches = text.match(pattern);
document.writeln(matches.index); //0
document.writeln(matches[0]); //"oo"
document.writeln(pattern.lastIndex); //0
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Essential Types
JavaScript Book
Essential Types
String:
- The String Type
- String length property
- String charAt()
- String charCodeAt()
- String concat()
- String slice()
- String substr()
- String substring()
- String indexOf()
- String lastIndexOf()
- String trim() Method
- String toLowerCase()
- String toLocaleLowerCase()
- String toUpperCase()
- String toLocaleUpperCase()
- String match()
- String search()
- String replace()
- String split()
- String localeCompare() Method
- String fromCharCode() Method
- String HTML Methods