.match(pattern)
Description
Parameters
Usage On Strings
str = "The rain in Spain"
result = str.match("/ain/g")
log result
// ["ain", "ain"]
// Returns all matches with global flag
result = "[email protected]".match("/^[^@]+@[^@]+\.[^@]+$/")
log result
// ["[email protected]"]
// Email validation example
result = "Hello World".match("/(\w+)\s(\w+)/")
log result
// ["Hello World", "Hello", "World"]
// Capturing groups example
result = "ABC123".match("/[0-9]+/")
log result
// ["123"]
// Matching numbers
// Common flags:
// g - Global search (find all matches rather than stopping after the first match)
// i - Case-insensitive search
// m - Multiline search
result = "Hello hello HELLO".match("/hello/gi")
log result
// ["Hello", "hello", "HELLO"]Last updated