String regex methods use regular-expression patterns.
Invalid regex patterns raise a runtime error.
Checks whether the pattern matches the string.
| Argument | Type | Description |
|---|---|---|
| `pattern` | string | Regular-expression pattern. |
Returns: boolean-style number.
Example:
'abc123'.match('[0-9]+'); // true 'abc'.match('[0-9]+'); // false
Returns the first text matched by the pattern.
| Argument | Type | Description |
|---|---|---|
| `pattern` | string | Regular-expression pattern. |
Returns: string. If there is no match, returns an empty string.
Example:
'abc123def'.find('[0-9]+'); // '123'
Replaces all regex matches with replacement text.
| Argument | Type | Description |
|---|---|---|
| `pattern` | string | Regular-expression pattern. |
| `replacement` | string | Replacement text. |
Returns: string.
Example:
'abc123def'.replace('[0-9]+', ''); // 'abcdef'
Previous: String Formatting Methods