We will learn to match a text value using IsMatch, Match, and MatchAll functions in Canvas Apps. Before we start, make sure to subscribe to CRM Crate to that you can stay up to date in the field of Power Platform.
What is Power FX?
Microsoft’s Power Fx is the low-code language that will be used across Power Platform. It’s a strong-typed, general-purpose, declarative, and functional programming language. Power Fx is expressed in user-friendly text. It’s a low-code language that citizen developers & makers can work with directly in an Excel-like formula bar or Visual Studio Code text window.
It enables a complete range of development from no-code for those who have never programmed before to “pro-code” for the seasoned professional, with no learning or rewriting cliffs in between, enabling diverse teams to collaborate and save time and expense.
Understanding IsMatch(), Match(), MatchAll() function to match a text in Canvas App
IsMatch ()
The IsMatch function tests whether a text string matches a pattern that can comprise ordinary characters, predefined patterns, or a regular expression.
For example, you can confirm whether the user has entered a valid email address before the result is saved to your data source. If the entry doesn’t match your criteria, add other controls that prompt the user to correct the entry.
Match() & MatchAll()
The Match and MatchAll functions return what was matched, including sub-matches. Use Match to extract the first text string that matches a pattern and MatchAll to extract all text strings that match. You can also extract sub-matches to parse complex strings.
Understanding different patterns available in Matching functions
- The main component used in these functions is in stating the pattern to match. We can describe the pattern in a text or a string as combination of:
– Predefined patterns, such as Email, MultipleDigits, or Letter.
– Regular-expression codes, such as “\d+\s+\d+” or “[a-z]+”.
– Ordinary characters, such as “crm” or “123”.
List of available Ordinary Patterns:
Special character | Description |
---|---|
. | dot or period |
? | question mark |
* | asterisk |
+ | plus |
( ) | parentheses |
[ ] | square brackets |
{ } | curly braces |
^ | caret |
$ | dollar sign |
| | vertical bar or pipe |
\ | backslash |
Example of IsMatch() function with Ordinary Patterns:
Formula | Description | Result |
---|---|---|
IsMatch( TextInput.Text, "CRM Crate" ) | Tests whether the user’s input matches, exactly, the string “CRM Crate”. | true |
IsMatch( TextInput.Text, "Prashant irlotkar" ) | Tests whether the user’s input matches, exactly, the string “Prashant Tirlotkar”. | false |
IsMatch( TextInput.Text, "CRM", Contains ) | Tests whether the user’s input contains the word “CRM” (case sensitive). | false |
IsMatch( TextInput.Text, " | Tests whether the user’s input contains the word “CRM” (case insensitive). | true |
List of available Predefined Patterns:
Match enum | Description | Regular expression |
---|---|---|
Any | Matches any character. | . |
Comma | Matches a comma. | , |
Digit | Matches a single digit (“0” through “9”). | \d |
Matches an email address that contains an “at” symbol (“@”) and a domain name that contains a dot (“.”) | .+\@.+\\.[^\\.]{2,} | |
Hyphen | Matches a hyphen. | \- |
LeftParen | Matches a left parenthesis “(“. | \( |
Letter | Matches a letter. | \p{L} |
MultipleDigits | Matches one or more digits. | \d+ |
MultipleLetters | Matches one or more letters. | \p{L}+ |
MultipleNonSpaces | Matches one or more characters that don’t add whitespace (not space, tab, or newline). | \S+ |
MultipleSpaces | Matches one or more characters that add whitespace (space, tab, or newline). | \s+ |
NonSpace | Matches a single character that doesn’t add whitespace. | \S |
OptionalDigits | Matches zero, one, or more digits. | \d* |
OptionalLetters | Matches zero, one, or more letters. | \p{L}* |
OptionalNonSpaces | Matches zero, one, or more characters that don’t add whitespace. | \S* |
OptionalSpaces | Matches zero, one, or more characters that add whitespace. | \s* |
Period | Matches a period or dot (“.”). | \. |
RightParen | Matches a right parenthesis “)”. | \) |
Space | Matches a character that adds whitespace. | \s |
Tab | Matches a tab character. | \t |
Example of IsMatch() function with Predefined Patterns:
Formula | Description | Result |
---|---|---|
IsMatch( "123-45-7890", Digit & Digit & Digit & Hyphen & Digit & Digit & Hyphen & Digit & Digit & Digit & Digit ) | Matches a United States Social Security Number | true |
IsMatch( "joan@contoso.com", Email ) | Matches an email address | true |
IsMatch( "123.456", MultipleDigits & Period & OptionalDigits ) | Matches a sequence of digits, a period, and then zero or more digits. | true |
IsMatch( "123", MultipleDigits & Period & OptionalDigits ) | Matches a sequence of digits, a period, and then zero or more digits. A period doesn’t appear in the text to match, so this pattern isn’t matched. | false |
Validate the implementation of IsMatch() function in Canvas App
The below animation describes the working of IsMatch() function in Canvas App.