Regular expression can be constructed using a literal which consists of a pattern enclosed between slashes, as follows: re = /ab+c/;. It is probably a good idea to store a regex in a variable if you plan to use the regular expression multiple times. This prevents the requirement to compile the regular expression each time.


Flag Description
i Case-insensitive search.
m Multi-line search.
s Allows . to match newline characters.


Function Description
test Test if a given string has a match with the regular expression.
Function Description
regex Create a new regex.
is_regex Test if a given value is of type regex.

This code uses a regular expression for an oversimplified email check:

// Note: the email check is oversimplified, do not use in production
email_test = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;

/* example usage of our 'email_test' */

Return value in JSON format