H BNDDIR('QC2LE') DFTACTGRP(*NO) D regex_t DS qualified dim(1) align D re_nsub 10U 0 D re_comp * inz(*NULL) D re_cflags 10I 0 D re_erroff 10U 0 D re_len 10U 0 D re_ucoll 10I 0 Dim(2) D re_lsub * Inz(*NULL) D lsub_ar 10I 0 Dim(16) D esub_ar 10I 0 Dim(16) D reserved1 * Inz(*NULL) D re_esub * Inz(*NULL) D re_specchar * Inz(*NULL) D re_phdl * Inz(*NULL) D comp_spc 1A Dim(112) D re_map 1A Dim(256) D re_shift 5I 0 D re_dbcs 5I 0 D regmatch_t DS occurs(maxEntry) align start offset D rm_so 10I 0 D rm_ss 5I 0 D rm_eo 10I 0 end offset D rm_es 5I 0 D regcomp PR 10I 0 extproc('regcomp') D preg * value D pattern * value options(*string) D cflags 10I 0 value D regexec PR 10I 0 extproc('regexec') D preg * value D string * value options(*string) D nmatch 10U 0 value d pmatch * value D eflags 10I 0 value D regerror PR 10U 0 extproc('regerror') D errcode 10I 0 value D preg * value D errbuf * value D errbuf_size 10I 0 const D regfree PR extproc('regfree') D preg * value D REG_BASIC C const(X'00') D REG_EXTENDED C const(X'01') D REG_ICASE C const(X'02') D REG_ICASEX C const(X'03') D REG_NEWLINE C const(X'04') D REG_NOSUB C const(X'08') D REG_ALT_NL C const(X'10') D maxEntry c const(10) D preg S * D pmatch S * D string S 256A D len S 10I 0 D rc S 10I 0 D nmatch S 10U 0 inz(maxEntry) D buf S 256A D pattern S 50A D temp s 100a varying D x s 10i 0 /free *inlr = *on; string = 'This is a line of text 111111. T2his i2s al2so a2 lin2e' + 'will eventuallyrunoverats string is longer than normal. Somwer' + 'some more text'+ x'0D25' + 'over at some point simple stri.'+ 'This is the last sentence in the paragraph.'; pattern = '(\S\S{40,}|.{1,40})(\s+|$)'; %occur(regmatch_t) = 1; preg = %addr(regex_t); pmatch = %addr(regmatch_t); // Compile RE rc = regcomp(preg: %trim(pattern): REG_ICASEX); if rc <> 0; regerror(rc: preg: %addr(buf): %size(buf)); temp = 'comp() failed with: ' + %str(%addr(buf)); return; endif; // Execute RE rc = regexec(preg: %trim(string): nmatch: pmatch: 0); if rc <> 0; regerror(rc: preg: %addr(buf): %size(buf)); regfree(preg); temp = 'regexec() failed with: ' + %str(%addr(buf)); return; endif; for x = 1 to nmatch; %occur(regmatch_t) = x; // Done processing if these are negative if rm_eo = -1 or rm_so = -1; leave; endif; len = rm_eo - rm_so; rm_so = rm_so + 1; temp = %subst(string: rm_so: len); endfor; regfree(preg); return; /END-FREE