× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi all,

I am trying to use regular expressions to take a long text string (from a
browser text box) and "splice" it out to fit into multiple DB2 records which
are 40 characters long each. I have found articles by Scott Klement and Bob
Cozzi and they have gotten me pretty far, but I seem to be getting odd
results and am wondering if anybody can see where I might be wrong.

Basically I have an all inclusive program (see below) that hard codes a long
string. Then I compile the regex and execute it. Both of these steps are
successful but when I loop through it with a FOR opcode I get weird results
where the first entry of regmatch_t is as expected, but the second and the
third aren't what I am expecting. For the second I would expect a starting
string offset different than the first, but it is not. For their third
iteration I get it matching up with a single character.

Any glaring mistakes given my general need?

Aaron Bartell
http://mowyourlawn.com

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
D cflags 10I 0 value

D regexec PR 10I 0 extproc('regexec')
D preg * value
D string * value
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.' + x'00';
pattern = '(\S\S{40,}|.{1,40})(\s+|$)' + x'00';
/END-FREE
c 1 occur regmatch_t
/FREE
preg = %addr(regex_t);
pmatch = %addr(regmatch_t);

// Compile RE
rc=regcomp(preg:%addr(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: %addr(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;
/end-free
c x occur regmatch_t
/FREE
// 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

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.