User Tools

Site Tools


match_return_matching_values_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== MATCH (compare matching values) ====== Previous pageReturn to chapter overviewNext page

MATCH( first, second [, mode ] )

blk2blue.jpg

MATCH Returns true or false based on a comparison of the first two parameters passed.
first A string containing data to compare against the second parameter. String constants must be enclosed in single quotes.
second A string containing data to compare against the first parameter. For Wild and Regular modes second must contain the pattern or expression to match. String constants must be enclosed in single quotes.
mode An integer constant or equate which specifies the method of comparison. If omitted, a wild card comparison is the default.

The MATCH procedure returns true or false as to whether the first and second parameters match according to the comparison mode specified. The following mode value EQUATEs are listed in EQUATES.CLW:

Match:Simple A straight-forward equivalence comparison (first = second), which is most useful when combined with Match:NoCase
Match:Wild (default) A wild card match with the second parameter containing the pattern that can contain asterisk (*) to match 0 or more of any character, and question mark (?) to match any single character.
Match:Regular A regular expression match where the second parameter contains the regular expression. Repeated usage with the same regular expression value is optimized (to avoid recompiling the expression).
Match:Soundex A standard soundex comparison of the two strings, returning true if they have the same soundex value.
Match:NoCase Add to the mode for a case insensitive match (except Soundex).

Regular Expression Operators

black.jpg

Regular expressions are used to describe patterns in text. The following characters are regular expression operators (or metacharacters) used to increase the power and versatility of regular expressions.

Caret matches the beginning of the string or the beginning of a line within the string. For example:^@chapter
matches the “@chapter” at the beginning of a string.
$ Dollar sign is similar to the caret, but it matches only at the end of a string or the end of a line within the string. For example:p$ matches a record that ends with a p.
. Period (.) matches any single character except a new line. For example: .P matches any single character followed by a P in a string. Using concatenation we can make regular expressions like 'U.A', which matches any three-character sequence that begins with 'U' and ends with 'A'.
[…] This is called a character set. It matches any one of the characters that are enclosed in the square brackets. For example: [MVX] matches any one of the characters M, V, or X in a string. Ranges of characters are indicated by using a hyphen between the beginning and ending characters, and enclosing the whole thing in brackets. For example:[0-9] matches any digit. To match '-', write it as '—', which is a range containing only '-'. You may also give '-' as the first or last character in the set. To match '', put it anywhere except as the first character of a set. To match a ']', make it the first character in the set. For example: []d^]matches either ']', 'd' or ''.
[ …] This is a complemented character set. The first character after the [ must be a . It matches any characters except those in the square brackets (or newline). For example: [^0-9] matches any character that is not a digit.
Vertical bar is the alternation operator and it is used to specify alternatives. For example: ^P|[0-9]matches any string that matches either P or [0-9]. This means it matches any string that contains a digit or starts with P. The alternation applies to the largest possible regexps on either side. No spaces are allowed between strings and the alternation operator.
{…} Brackets are used for grouping in regular expressions as in arithmetic. They can be used to concatenate regular expressions containing the alternation operator, .
* Asterisk means that the preceding regular expression is to be repeated as many times as possible to find a match. For example: ph* applies the * symbol to the preceding h and looks for matches to one p followed by any number of h's. This will also match just p if no h's are present. The * repeats the smallest possible preceding expression (use parentheses if you wish to repeat a larger expression). It finds as many repetitions as possible. For example: (c[ad][ad]*r x) matches a string of the form (car x), (cdr x), (cadr x), and so on.
+ Plus sign is similar to *, but the preceding expression must be matched at least once. This means that: wh+y would match “why” and “whhy” but not “wy,” whereas wh*y would match all three of these strings. This is a simpler way of writing the last * example: (c[ad]+r x)
? Question mark is similar to *, but the preceding expression can be matched once or not at all. For example: fe?d will match fed and fd, but nothing else.
\ Backslash is used to suppress the special meaning of a character when matching. For example: \$ matches the character $.

In regular expressions, the *, +, and ? operators have the highest precedence, followed by concatenation, and finally by |.

NoteBox.jpg

There is now extended support for the MATCH function when used with the FILTER attribute of any VIEW structure that accesses SQL and ODBC back ends. For more detailed information, see the Use of MATCH with PROP:Filter and SQL Databases help topic.

Return Data Type: LONG

Example:

A STRING('Richard')
B STRING('RICHARD')
C STRING('R*')
D STRING('[A-D]')
ListHave1    STRING('IN,OH,KY,TN,PA')
ListHave2    STRING('WI,MN,IA,SD,ND')
StatesWanted STRING('NJ|NY|PA|DE')
RV           BYTE !Return Value
X            BYTE
Y            BYTE
EmployeeName STRING('Tom Thumb')
EMailAddr    STRING('bob@softvelocity.com')
  CODE
  RV = MATCH(A,B,Match:Simple+Match:NoCase)   !Returns true - case insensitive match
  RV = MATCH(A,B,Match:Soundex)               !Returns true - same soundex values
  RV = MATCH(A,C)                             !Returns true - wildcard match
   
  RV=MATCH('Fireworks on the fourth', '{{4|four}th', Match:Regular+Match:NoCase)  !returns True
  RV=MATCH('July 4th fireworks', '{{4|four}th',Match:Regular+Match:NoCase)        !returns True
   
  X = STRPOS(ListHave1,StatesWanted,Match:Regular+Match:NoCase)   ! X = 13
  Y = STRPOS(ListHave2,StatesWanted,Match:Regular+Match:NoCase)   ! Y = 0
   
  IF MATCH(EmployeeName,'^Th?om{{as|my}?{{ }+', Match:Regular+Match:NoCase)
     Message('Welcome Tom Thom Thomas or Tommy')
  END
   
  !Regular expression for testing an Email Address as valid. 
  !1. The name portion can contain the characters: A-Z 0-9 -._ 
  !2. Then must have an @ 
  !3. Then repeating groups containing: A-Z 0-9 -._ 
  !4. A period and 2, 3, 4 letters 
   
  RV = MATCH(UPPER(CLIP(eMailAddr)),'^[-A-Z0-9._]+@{{[-A-Z0-9._]+\.}+[A-Z][A-Z][A-Z]?[A-Z]?$'
 

See Also:

STRPOS

INSTRING

match_return_matching_values_.htm.txt · Last modified: 2021/05/06 02:01 by carlbarnes