How to use the textmatch function?
textmatch
function?
How to use the 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
textmatch
:
Regular Expression Constraints used with -
^ : check match at the beginning of the string
Example String Pattern Match Note abc ^a Yes The match is successful because the alphabet “a” is found at the beginning of the String. bac ^a No
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 String | Pattern | Match | Note |
abc | a$ | No | The match is unsuccessful because the alphabet “a” is not found at the end of the String. |
bac | c$ | Yes | The match is successful because the alphabet “c” is found at the beginning of the String. |
textmatch
:
Metacharacters used with -
| : alternation or choice between elements.
Example String Pattern Match Note a a|b Yes The match is successful because the pattern “a|b” has “a” string. a c|d No The 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 String Pattern Match Note a [abc] Yes The match is successful because “a” is found in the pattern. d [abc] No The match is unsuccessful because “d” is not found in the pattern. 5 [0-9] Yes The match is successful because “5” is found in the decimal digit series between 0 to 9. a [a0-9] Yes The match is successful because “a” is found in the pattern of a and 0 to 9 decimal digit series. z [a-z0-9] Yes The 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] Yes The 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 Pattern Match Note x x* yes The match is successful because “x” is found in the pattern. a x* yes The match is successful because no “x” is found in the pattern. xxxx x* yes The 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 Pattern Match Note x x+ yes The match is successful because “x” is found in the pattern. a x+ no The match is unsuccessful because “x” is not found in the pattern. xxxx x+ yes The 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 Pattern Match Note x x? yes The match is successful because “x” is found in the pattern. a x? yes The match is successful because no “x” is found in the pattern. xxxx x? yes The 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 Pattern Match Note x x{2} no The match is unsuccessful because “x” is not found 2 times in the pattern. xx x{1} yes The match is successful because “x” is found 1 time in the pattern. a x{0} yes The 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 Pattern Match Note x x{1,} yes The match is unsuccessful because “x” is found 1 time in the pattern. x x{2,} no The match is unsuccessful because “x” is not found 2 times in the pattern. x x{0,} yes The 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 Pattern Match Note x x{1,2} yes The match is successful because the string contains “x” and the pattern requires the same to be matched. x x{2,3} no The match is unsuccessful because the string contains only “x”, while the pattern requires at least “xx” to be matched. xxxx x{1,2} yes The 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 withtextmatch
:
\\d | Match any digit |
\\s | Matches any whitespace character |
\\w | Matches any word character |
\\D | Match any non-digit |
\\S | Matches any non-whitespace character |
\\W | Matches any non-word character |