test

This function is deprecated and should be replaced with test(..) on type regex.

Test if a string matches a given regular expression and return true or false.

This function does not generate a change.

Function

str.test(regex)

Arguments

Argument Type Description
regex regex (required) The regular expression to test against the string.

Return value

true if there is a match between the string and the specified regular expression, otherwise false.

Example

Examples using test():

[
    'Hello world!!'.test(/^hello/),
    'Hello world!!'.test(/^hello/i),
];

Return value in JSON format

[
    false,
    true
]