Difference between revisions of "Regular Expression Pattern Matching Using !Match"

From Vital Soft Wiki
Jump to: navigation, search
(Regular Expression Pattern Matching)
Line 9: Line 9:
 
  !match(!trim(MEMBER-FILE.E-MAIL), "^[^ @]+@[^ @\.]+\.[^ @\.]+$") = 0 AND MEMBER-FILE.E-MAIL <> " "
 
  !match(!trim(MEMBER-FILE.E-MAIL), "^[^ @]+@[^ @\.]+\.[^ @\.]+$") = 0 AND MEMBER-FILE.E-MAIL <> " "
  
The above example will not find all invalid email addresses, but it will find those that don't match the pattern.  The equals zero, means that the pattern was not matched.  The pattern does the following:
+
The above example will not find all invalid email addresses, but it will find those that don't match the pattern.  The equals zero, means that the pattern was not matched.  See below for an explanation of this pattern:
 
     {| class="wikitable" style="border-spacing: 2,2,2,2;"
 
     {| class="wikitable" style="border-spacing: 2,2,2,2;"
 
     |Pattern ||Explanation of pattern
 
     |Pattern ||Explanation of pattern

Revision as of 23:10, 19 January 2023

Regular Expression Pattern Matching

The AskPlus !match function uses the Perl Compatible Regular Expression (PCRE) engine to perform patching. If a match is found, the function returns the position of the match in the string. If no match is found, zero is returned. The basic syntax of !match is:

!match(string, pattern)

An example of using !match to find invalid email addresses is shown below:

!match(!trim(MEMBER-FILE.E-MAIL), "^[^ @]+@[^ @\.]+\.[^ @\.]+$") = 0 AND MEMBER-FILE.E-MAIL <> " "

The above example will not find all invalid email addresses, but it will find those that don't match the pattern. The equals zero, means that the pattern was not matched. See below for an explanation of this pattern:

Pattern Explanation of pattern
^ Start the match at the beginning of the string
[^ @]+ Match at least one (+) character that is not a blank or the @ character ([^ @] is a negated character class)
@ Match the @ character
[^ @\.]+ Match at least one (+) character that is not a blank, the @ character, or a period.
\. Match a period (dot).
[^ @\.]+ Match at least one (+) character that is not a blank, the @ character, or a period.
$ Match until the end of the string. The !trim is needed to ensure trailing blanks are ignored.