MicroStrategy ONE
Match
The Match
function uses regular expressions to search a string for a pattern of characters and returns any matches that are found.
Syntax
Match <Group=0,Instance=1>(
Argument
,
Find
)
Where:
Argument
is a metric, fact, column, or string representing the text strings that are searched for matches.Find
is a metric, fact, column, or string that provides a regular expression used to searched the strings returned byArgument
. The regular expressions supported by this function conform to the standards of the International Components for Unicode. For information about these regular expression standards and syntax, see http://userguide.icu-project.org/strings/regexp.Group
is a parameter that determines which group within the regular expression is returned. The groups in a regular expression are each set of characters enclosed by parentheses()
and are ordered left to right. By default, theGroup
parameter is defined as0
and the entire string that is matched is returned. If you defineGroup
as1
, only the first group from the left of the regular expression is returned. If you defineGroup
to a value greater than the number of groups in the regular expression, no results are returned. For example if there is one group butGroup
is defined as2
, no results are returned.Instance
is a parameter that determines which instance of the matching results are returned. By default,Instance
is defined as1
and the first match is returned. If you defineInstance
to a value greater than the number of matching results, no results are returned. For example if there are two matches butInstance
is defined as3
, no results are returned.
For information about the syntax used in your specific database, the MicroStrategy and Database Support for Functions and see the section that corresponds to your database.
Example
Consider the string of text "Telephone: 703-555-1234, Fax: 704-555-6789". You can search for and return various parts of the telephone numbers in this string using regular expressions. The regular expression (\d+)[-\b](\d+)[-\b](\d+)
breaks up the three sets of digits in a phone number into separate groups, which can be returned using the Match
function.
See http://userguide.icu-project.org/strings/regexp for information on the regular expression standards and syntax.
For example:
-
Match("Telephone: 703-555-1234, Fax: 704-555-6789", "(\d+)[-\b](\d+)[-\b](\d+)")
By default this returns the entire string that is the first match, which is 703-555-1234.
-
Match<Group=1>("Telephone: 703-555-1234, Fax: 704-555-6789", "(\d+)[-\b](\d+)[-\b](\d+)")
This returns the first group (the first search criteria in parentheses) from the first occurrence, which is 703.
-
Match<Instance=2, Group=3>("Telephone: 703-555-1234, Fax: 704-555-6789", "(\d+)[-\b](\d+)[-\b](\d+)")
This returns the third group (the third search criteria in parentheses) from the second occurrence, which is 6789.