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:
- H OPTION(*NOSHOWCPY:*NOEXPDDS:*NODEBUGIO:*SRCSTMT)
- H DATFMT(*ISO) TIMFMT(*ISO) DFTACTGRP(*NO)
- H CVTOPT(*VARCHAR:*NODATETIME)
- H THREAD(*SERIALIZE)
- H BndDir('QC2LE')
-
- /Include PGMSRC,REGEXP_H
-
- D findThis S 64 Varying Inz('one')
- D findWithin S 64 Varying Inz('There is none but +
- D the one.')
-
- D regEx DS LikeDS(regex_t)
- D match DS LikeDS(regmatch_t) dim(5)
- D I S 10U 0
- D rc S 10I 0
-
- /Free
-
- rc = regcomp(regEx: findThis
- : REG_EXTENDED
- ) ;
- if (rc = *Zero) ;
- rc = regexec(regEx
- : findWithin
- : %Elem(match)
- : match(1)
- : *Zero
- ) ;
- If (rc = *Zero) ; // Match(es) found
- For I = 1 to %Elem(match) ;
- If match(I).rm_so < 0 ;
- Leave ;
- EndIF ;
- // Do something with this matching data...
- EndFOR ;
- EndIF ;
- EndIF ;
- *INLR = *On ;
- Return ;
-
- /End-free
|
|
|