match Function
Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
Searches for a string or expression within another string.
int match(str pattern, str text)
Parameters
Parameter |
Description |
---|---|
pattern |
The string or expression for which to search. |
text |
The string to search. |
Return Value
1 if the pattern is located in the string; otherwise, 0.
Remarks
The search is case insensitive.
The following special characters can be used to create the pattern for the pattern parameter:
Character |
Description |
---|---|
\ |
A backslash nullifies, or escapes, the special treatment of special characters so that the special character can be matched like a normal letter. A pair of backslashes is translated into one non-special backslash. For example: match("ab$cd","ab$cd"); //returns 0 match("ab\$cd","ab$cd"); //returns 0 - the backslash is not escaped match("ab\\$cd","ab$cd"); //returns 1 - the backslash and dollar sign are escaped |
< or ^ |
A left angle bracket or a circumflex at the start of an expression is used to match the start of a line. For example: match("<abc","abcdef"); //returns 1 match("<abc","defabc"); //returns 0 match("^abc","abcdef"); //returns 1 match("^abc","defabc"); //returns 0 |
> or $ |
A right angle bracket or a dollar sign at the end of the expression is used to match the end of a line. For example: match("abc>","abcdef"); //returns 0 match("abc>","defabc"); //returns 1 |
? or . |
A question mark or a period will match any one character in the same position. For example: match("abc.def","abc#def"); //returns 1 match("colou?r","colouXr"); //returns 1 |
:x |
A colon specifies a group of characters to be matched, indicated by the character that follows immediately after. |
:a |
Sets the match to letters. For example: match("ab:acd","ab#cd"); //returns 0 match("ab:acd","abxyzcd"); //returns 0 match("ab:acd","abxcd"); //returns 1 |
:d |
Sets the match to numeric characters. For example: match("ab:dcd","ab3cd"); //returns 1 match("ab:dcd","ab123cd"); //returns 0 match("ab:dcd","abcd"); //returns 0 |
:n |
Sets the match to alphanumeric characters. For example: match("ab:ncd","ab%cd"); //returns 0 match("ab:ncd","ab9cd"); //returns 1 match("ab:ncd","abXcd"); //returns 1 |
:SPACE |
Where SPACE is the character ' '. Sets the match to blanks, tabulations, and control characters such as Enter (new line). For example: match("ab: cd","ab cd"); //returns 1 match("ab: cd","ab\ncd"); //returns 1 match("ab: cd","ab\tcd"); //returns 1 match("ab: cd","ab cd"); //returns 0 - only the first space is matched |
* |
An expression followed by an asterisk requires a match for zero, one, or more occurrences of the preceding expression. For example: match("abc*d","abd"); //returns 1 match("abc*d","abcd"); //returns 1 match("abc*d","abcccd"); //returns 1 match("abc*d","abxd"); //returns 0 |
+ |
An expression followed by a plus sign requires a match for one or more occurrences of the preceding expression. For example: match("abc+d","abd"); //returns 0 match("abc+d","abcd"); //returns 1 match("abc+d","abcccd"); //returns 1 match("abc+d","abxd"); //returns 0 |
- |
An expression followed by a minus sign requires a match for zero or one occurrence of the preceding expression. In other words, the preceding expression is optional. For example: match("colou-r","color"); //returns 1 match("colou-r","colour"); //returns 1 |
[] |
Matches a single character with any character contained within the brackets.A range of characters can be specified by two characters separated by a minus sign. For example, [a-z] matches all letters between a and z, [0-9] matches a digit, [0-9a-f] matches a hexadecimal digit. match("[abc]","apple"); //returns 1 - matches the 'a' in apple match("[abc]","kiwi"); //returns 0 - kiwi does not contain an a, b, or c match("gr[ae]y","grey"); //returns 1 - also matches "gray" match("gr[ae]y","graey"); //returns 0 - only one character between "gr" and "y" is matched. |
[^] |
If the first character in a text within square brackets is a circumflex (^), the expression matches all characters except those contained within the brackets. match("[^bc]at","bat"); //returns 0 match("[^bc]at","hat"); //returns 1 match("[^abc]","bat"); //returns 1 - anything but a, b, or c is matched. The t is matched |
Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).