matchgroup
matchgroup(string
,regexp
,group
)
The MATCHGROUP function has the following arguments:
string
The string to match against the regular expression.
regexp
The regular expression to be used for matching.
group
The number of the matching capture group that should be extracted from the string.
Tests if the string matches the regular expression. If it does, the function returns the substring in th capture group specified by the group argument.
If the string does not match the pattern, or if the group does not exist the function will return an empty string.
See the section on Regular expressions for a description of the matching patterns.
Formula |
Description |
Result |
---|---|---|
matchgroup('foobar', 'foo(.*)',1) |
Test if 'foobar' matchgroup to 'foo(.*)' and return the value from the first capture group. |
'bar' |
matchgroup('Oops', 'foo(.*)',1) |
Test if 'Oops' matchgroup to 'foo(.*)' and return the value from the first capture group. The regexp does not match so the function return ''. |
'' |