home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / csso0301.zip / SAMPLES / REX / REGULAR.CMD
OS/2 REXX Batch file  |  2000-02-23  |  1KB  |  52 lines

  1. @goto exec
  2. /*  Copyright (c) 2000 IBK-Landquart-Switzerland. All rights reserved.
  3.  *
  4.  *  Module      :  Regular.cmd/Regular.bat
  5.  *  Application :  Sample showing use of regular expressions library
  6.  *                 and how to embedd CSS into a CMD or BAT file.
  7.  *  Author      :  Peter Koch, IBK
  8.  *
  9.  *  Date        Description                                 Who
  10.  *  --------------------------------------------------------------------------
  11.  *  Feb 2000    First release                               P.Koch, IBK
  12.  */
  13. #loadLibrary 'KcSysLib'
  14. #loadLibrary 'KcStrLib'
  15. #loadLibrary 'KcRexLib'
  16.  
  17. main()
  18. {
  19.    const pattern = '\\(sim[a-z]le\\) \\1';
  20.    const string  = 'a very simple simple simple string';
  21.  
  22.    sysLog('compile regular expression');
  23.    var rx = rexOpen(pattern);
  24.    var match[6][2];
  25.  
  26.    sysLog('find and display match');
  27.    sysLogLevel(+1);
  28.    var m = rexMatch(rx, string, 6, match);
  29.    if (m) {
  30.       for (var i = 0; i < m; i++)
  31.          sysLog(
  32.             match[i][0]+' '
  33.             +match[i][1]+" '"
  34.             +strSubString(string,match[i][0], match[i][1])
  35.             +"'"
  36.          );
  37.    } else
  38.       sysLog('no match found');
  39.    sysLogLevel(-1);
  40.  
  41.    sysLog('close and release mem');
  42.    rexClose(rx);
  43. } // main
  44.  
  45. /*
  46.  * This section is run by the command processor. We start the
  47.  * CSS executive here and pass any parameters.
  48.  *
  49. :exec
  50. @css %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  51. @rem */
  52.