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 by Argument. 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, the Group parameter is defined as 0 and the entire string that is matched is returned. If you define Group as 1, only the first group from the left of the regular expression is returned. If you define Group to a value greater than the number of groups in the regular expression, no results are returned. For example if there is one group but Group is defined as 2, no results are returned.
  • Instance is a parameter that determines which instance of the matching results are returned. By default, Instance is defined as 1 and the first match is returned. If you define Instance to a value greater than the number of matching results, no results are returned. For example if there are two matches but Instance is defined as 3, 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.