Start of README v1.0

REGEXP REGULAR EXPREESSION function


REGEXP was developed by McKay Software Services Ltd www.mckaysoftware.ie

This describes the purpose and components of REGEXP and how to download, install and use the REGEXP function.

REGEXP is a single function which executs a regular expression pattern on a string of text.
The text string and the pattern are the only two parameters input.
A return code indicates success or failure.

    CONTENTS

  1. PURPOSE
  2. METHOD
  3. REGEXP function call
  4. ERROR messages
  5. SAVEFILE
  6. SHIPPING LIST
  7. Change Log

  1. PURPOSE
  2. REGEXP allows developers on AS400 / ISeries to use a fuller set of regular expressions than is currently available.
    It is called within a program or module.
    ===>CONTENTS

  3. METHOD
  4. REGEXP is a single function which executes a regular expression pattern on a string of text.
    Pointers to the text string and the pattern string are the only two parameters input.
    Note that the text string and the pattern must be terminated with a null character. A return code indicates success or failure.
    REGEXP uses the following literal characters and punctuation characters to effect a match ...

    Literal Characters ...

    \0zeroNULL
    \tlowercase tTAB
    \nlowercase nNew Line
    \vlowercase vVertical tab
    \flowercase fForm Feed
    \rlowercase rCarriage Return
    \xnnlowercase xHexadecimal character represented by nn
    \dlowercase dmatches any digit 0-9
    \Duppercase Dmatches what is not a digit
    \wlowercase wmatches any alphanumeric, a-zA-Z0-9_
    \Wuppercase Wmatches what is not alphanumeric
    \clowercase cmatches any alphabetic, a-zA-Z
    \Cuppercase Cmatches what is not alphabetic, a-zA-Z
    \slowercase smatches any whitespace character
    \Suppercase Smatches any non-whitespace character

    Punctuation Characters ...
    ^caratmatch the beginning of a string or line
    $dollar signmatch the end of a string or line
    .stopwildcard - matches any character
    *asteriskzero or more matches
    +plusone or more matches
    ?question markthe match is optional, may or may not match
    |vertical baralternative (or)
    \back slashescape character, the following character has a specific meaning
    ( )round bracketssubexpression
    { }bracesnumber of occurrences to match
    [ ]square bracketssequence or range of characters to match



    ===>CONTENTS

  5. REGEXP function call

  6. REGEXP function call

            
    H bnddir('QC2LE')                                                 
                                                                      
    D   intotest      s            256                                
    D   inpattern     s            256                                
                                                                      
    d regexp          pr            10i 0 extproc('regexp')           
    d   xtotest                       *   value options(*string)      
    d   xpattern                      *   value options(*string)      
    d xreturn         s             10i 0                             
    d totest          s                   like(intotest)              
    d totestptr       s               *   inz(%addr(totest))          
    d pattern         s                   like(inpattern)             
    d patternptr      s               *   inz(%addr(pattern))         
                                                                      
    d cnull           c                   x'00'                       
                
     /free                      
                                                     
        intotest = 'myname@emailaddress.zxy';            
        inpattern = '\w+@\w+\.\w{2,3}$';                  
                                                     
        totest = %trim(intotest) + cnull;                
        pattern = %trim(inpattern) + cnull;              
                                                     
        xreturn = regexp (totestptr: patternptr);        
                                                     
        dsply xreturn; 
    		                   
        *inlr = *on;    
                       
     /end-free            
    




    The above is an example of how the REEGEXP might be used in a RPG program. Both input parameters are pointers and the strings pointed to must end with a null character.
    This example is in the save file as RX2.

    ===>CONTENTS


  7. ERROR messages

  8. A negative return code indicates an error, as follows ...

    -1REG_NOMATCHregexec() failed to find a match.
    -2REG_BADPATInvalid regular expression.
    -3REG_ECOLLATEInvalid collating element referenced.
    -4REG_ECTYPEInvalid character class type referenced.
    -5REG_EESCAPELast character in regular expression is a \.
    -6REG_ESUBREGNumber in \digit invalid, or error.
    -7REG_EBRACK[] imbalance.
    -8REG_EPAREN\( \) or () imbalance.
    -9REG_EBRACE\{ \} imbalance.
    -10REG_BADBRExpression between \{ and \} is invalid.
    -11REG_ERANGEInvalid endpoint in range expression.
    -12REG_ESPACEOut of memory.
    -13REG_BADRPT?, *, or + not preceded by valid regular expression.
    -14REG_ECHARInvalid multibyte character.
    -15REG_EBOL| anchor not at beginning of regular expression.
    -16REG_EEOL$ anchor not at end of regular expression.
    -17REG_ECOMPUnknown error occurred during regcomp() call.
    -18REG_EEXECUnknown error occurred during regexec() call.

    This table of error messages is taken from
      IBM's iSeries ILE C/C++ for iSeries
      Run-Time Library Functions
      Version 5
      SC41-5607-01

    ===>CONTENTS

  9. SAVEFILE
  10. The objects are provided in a savef MCKFNCSAVF.  To restore the savef, first create a savef on the AS400.  Use FTP with binary to upload the file to the savf you created.
    You may then move the contents to a library or libraries of your choice.
    ===>CONTENTS


  11. SHIPPING LIST
  12. The following objects are shipped in the savefile MCKFNCSAVF ...
    REGEXP1MODULEThis contains the function REGEXP.
    REGEXPSRCSRC PFSource file containing the sources for example programs RX1 and RX2, as well as the prototype for REGEXP

    ===>CONTENTS




  13. Change Log V1.0
     

===>CONTENTS



06 Aug 2010
©2010 McKay Software Services Ltd
www.mckaysoftware.ie
www.rpglanguage.com
End of README v1.0