The regex_match
method performs a regular expression match on a string.
regex_match( input, regex [, case] )
Argument | Description |
---|---|
input
|
(string) The string to match. |
regex
|
(string) The regular expression to match against. |
case
|
(boolean) A boolean that specifies whether the match is case-sensitive. The match is case sensitive by default (true ). |
One or more strings, or nil
.
If the string matches the regular expression, and the regular expression has no sub-matches, the full string is returned.
If the string matches the regular expression, and the regular expression has sub-matches, then only the sub-matches are returned.
If the string does not match the regular expression, there are no return values (any results are nil
).
You can assign multiple strings to a table. To assign the return values to a table, surround the function call with braces. For example:
matches = { regex_match( input, regex ) }
local r1, r2, r3 = regex_match( "abracadabra", "(a.r)((?:a.)*ra)" )
Results: r1="abr"
, r2="acadabra"
, r3=nil
local r1, r2, r3 = regex_match( "abracadabra", "a.r(?:a.)*ra" )
Results: r1="abracadabra"
, r2=nil
, r3=nil
|