Table of Contents



String Regex Methods

String regex methods use regular-expression patterns.

Invalid regex patterns raise a runtime error.


match(pattern)

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

find(pattern)

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'

replace(pattern, replacement)

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

Next: String Trim and Case Methods