midrange.com code scratchpad
Name:
Dennis Lovelady
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
02/03/2010 04:01:11 pm
IP:
Logged
Description:
Multiple-match regular expression not working as expected
Code:
  1.      H OPTION(*NOSHOWCPY:*NOEXPDDS:*NODEBUGIO:*SRCSTMT)
  2.      H DATFMT(*ISO) TIMFMT(*ISO) DFTACTGRP(*NO)
  3.      H CVTOPT(*VARCHAR:*NODATETIME)
  4.      H THREAD(*SERIALIZE)
  5.      H BndDir('QC2LE')
  6.                                                                        
  7.       /Include PGMSRC,REGEXP_H                                         
  8.                                                                        
  9.      D findThis        S             64    Varying Inz('one')          
  10.      D findWithin      S             64    Varying Inz('There is none but +
  11.      D                                                 the one.')      
  12.                                                                        
  13.      D regEx           DS                  LikeDS(regex_t)             
  14.      D match           DS                  LikeDS(regmatch_t) dim(5)   
  15.      D I               S             10U 0                             
  16.      D rc              S             10I 0                             
  17.                                                                        
  18.       /Free                                                            
  19.                                                                        
  20.        rc = regcomp(regEx: findThis                                    
  21.                   : REG_EXTENDED                          
  22.                    ) ;                                    
  23.        if (rc = *Zero) ;                                  
  24.           rc = regexec(regEx                              
  25.                      : findWithin                         
  26.                      : %Elem(match)                       
  27.                      : match(1)                           
  28.                      : *Zero                              
  29.                       ) ;                                 
  30.           If (rc = *Zero) ;           // Match(es) found  
  31.              For I = 1 to %Elem(match) ;                  
  32.                 If match(I).rm_so < 0 ;                   
  33.                    Leave ;                                
  34.                 EndIF ;                                   
  35.                 // Do something with this matching data...
  36.              EndFOR ;                                     
  37.           EndIF ;                                         
  38.        EndIF ;                                            
  39.        *INLR = *On ;                                      
  40.        Return ;                                           
  41.                    
  42.       /End-free    
© 2004-2019 by midrange.com generated in 0.009s valid xhtml & css