Used to match a regular expression against a string.
Method of String
Syntax
match( regexp )
Parameters
Parameter | Description |
---|---|
regexp | Name of the regular expression. It can be a variable name or a literal. |
Description
If you want to execute a global match, or a case insensitive match, include the g (for global) and i (for ignore case) flags in the regular expression. These can be included separately or together. The following two examples below show how to use these flags with match.
Note
If you execute a match simply to find true or false, use String.search or the regular expression test method.
Examples
Example 1. In the following example, match is used to find 'Chapter' followed by 1 or more numeric characters followed by a decimal point and numeric character 0 or more times. The regular expression includes the i flag so that case will be ignored.
This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1
'Chapter 3.4.5.1' is the first match and the first value remembered from (Chapter \d+(\.\d)*).
'.1' is the second value remembered from (\.\d).
Example 2. The following example demonstrates the use of the global and ignore case flags with match.
The returned array contains D, d.