How to use the textmatch function?

How to use the textmatch function?

textmatch is a function which evaluates the specified regular expression against a given string attribute. It returns true if the string contains the pattern. It uses double backslash (\\) to escape.

Syntax:

textmatch(string_attribute, regex_pattern)

Example:

azuread oauth2permissiongrant should-not-have textmatch(scope, "AppRoleAssignment.ReadWrite.All") = true

Regular Expression Constraints used with textmatch:

  • ^ : check match at the beginning of the string

    Example StringPatternMatchNote
    abc^aYesThe match is successful because the alphabet “a” is found at the beginning of the String.
    bac^aNo
    The match is unsuccessful because the alphabet “a” is not found at the beginning of the String.
    ^ Regular Expression Constraint used in the table
  • $ : check match at the end of the string

Example StringPatternMatchNote
abca$NoThe match is unsuccessful because the alphabet “a” is not found at the end of the String.
bacc$YesThe match is successful because the alphabet “c” is found at the beginning of the String.
$ Regular Expression Constraint used in the table

Metacharacters used with textmatch:

  • | : alternation or choice between elements.

    Example StringPatternMatchNote
    aa|bYesThe match is successful because the pattern “a|b” has “a” string.
    ac|dNoThe match is unsuccessful because the pattern “c|d” does not have “a” string.
    | Regular Expression Constraint used in the table
  • [ ] : specifies a character class.

    • If two characters in the list are separated by -, this is shorthand for the full range of characters between those two.

    • If the list begins with ^, it matches any single character not from the rest of the list.

      Example StringPatternMatchNote
      a[abc]YesThe match is successful because “a” is found in the pattern.
      d[abc]NoThe match is unsuccessful because “d” is not found in the pattern.
      5[0-9]YesThe match is successful because “5” is found in the decimal digit series between 0 to 9.
      a[a0-9]YesThe match is successful because “a” is found in the pattern of a and 0 to 9 decimal digit series.
      z[a-z0-9]YesThe match is successful because “z” is found in the pattern of a to z letters and 0 to 9 decimal digit series.
      A[^a-z0-9]YesThe match is successful because the string is any character that is not a lowercase a to z letters or 0 to 9 decimal digit series.
      [] Regular Expression Constraint used in the table
  • * : finds a sequence of none to multiple matches

    Example String PatternMatchNote
    xx*yesThe match is successful because “x” is found in the pattern.
    ax*yesThe match is successful because no “x” is found in the pattern.
    xxxxx*yesThe match is successful because “x” is found in the pattern multiple times.
    * Regular Expression Constraint used in the table
  • + : a sequence of one or more matches

    Example String PatternMatchNote
    xx+yesThe match is successful because “x” is found in the pattern.
    ax+noThe match is unsuccessful because “x” is not found in the pattern.
    xxxxx+yesThe match is successful because “x” is found multiple times in the pattern.
    + Regular Expression Constraint used in the table
  • ? : a sequence of none or one match

    Example String PatternMatchNote
    xx?yesThe match is successful because “x” is found in the pattern.
    ax?yesThe match is successful because no “x” is found in the pattern.
    xxxxx?yesThe match is successful because “x” is found in the pattern.
    ? Regular Expression Constraint used in the table
  • {m} : a sequence of exactly m matches of the atom

    Example String PatternMatch Note
    xx{2}noThe match is unsuccessful because “x” is not found 2 times in the pattern.
    xxx{1}yesThe match is successful because “x” is found 1 time in the pattern.
    ax{0}yesThe match was successful. The {0} causes the “x” to be ignored, the pattern is essentially an empty string.
    {m} Regular Expression Constraint used in the table
  • {m,} : a sequence of m or more matches

    Example String PatternMatchNote
    xx{1,}yesThe match is unsuccessful because “x” is found 1 time in the pattern.
    xx{2,}noThe match is unsuccessful because “x” is not found 2 times in the pattern.
    xx{0,}yesThe match was successful. The {0} causes the “x” to be ignored, the pattern is essentially an empty string.
    {m,} Regular Expression Constraint used in the table
  • {m, n} : a sequence of m through n (inclusive) matches, m cannot exceed n

    Example String PatternMatch Note
    xx{1,2}yesThe match is successful because the string contains “x” and the pattern requires the same to be matched.
    xx{2,3}noThe match is unsuccessful because the string contains only “x”, while the pattern requires at least “xx” to be matched.
    xxxxx{1,2}yesThe match is successful because the string contains “xx” and the pattern requires the same to be matched.
    {m,n} Regular Expression Constraint used in the table

    Class-shorthand escapes used with textmatch:

\\dMatch any digit
\\sMatches any whitespace character
\\wMatches any word character
\\DMatch any non-digit
\\SMatches any non-whitespace character
\\WMatches any non-word character
Class shorthand escapes used in textmatch
Share this Doc

How to use the textmatch function?

Or copy link

In this topic ...