match()

Checks if a string matches a given regular expression pattern.

Syntax

match(text, pattern)

Parameters

Parameter Type Description
text String The input string to check.
pattern String The regular expression pattern.

Return Value

Examples

Check if “abc123” contains digits

match("abc123", "[0-9]+");            // returns 1

Check if “hello” starts with “h”

match("hello", "^h");                 // returns 1

Check if “test” contains only numbers

match("test", "^[0-9]+$");            // returns 0

Check if “abc” contains lowercase letters

match("abc", "[a-z]+");               // returns 1

Check if “ABC” contains only uppercase letters

match("ABC", "^[A-Z]+$");             // returns 1

Check if the string “PlanetCNC” contains the substring “CNC”.

match("PlanetCNC", "CNC");            // returns 1

Check if the string starts with 'P' and ends with 'C'

match("PlanetCNC", "^P(.*)C$");       // returns 1

See also

str
strlen
padleft
padright
hex
bin
chr
match