× 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.



Rory,

The optional operator for running REGFREE each time is a good one. Thanks.

Let me think about it and see how best to implement that. Also I want to wait before I do any changes to monitor feedback.


Regards,
John McKay mba


----- Original Message ----- From: "Rory Hewitt" <rory.hewitt@xxxxxxxxx>
To: "RPG programming on the IBM i / System i" <rpg400-l@xxxxxxxxxxxx>
Sent: Friday, August 13, 2010 5:15 PM
Subject: Re: Regular Expressions


John,

I like the look of it, but I have a couple of 'concerns'.

1. Could you implement it so that you don't need to explicitly pass the
terminating null character? Easy to check within your REGEXP procedure, and
means that RPG programmers won't have to mess around themselves.

2. Following on from Dennis's concern(s), could you pass an (optional) final
parameter to say wheter you want to perform REGFREE? Then, REGEXP can check
whetherthe regexp has changed since the last time (and perform REGCOMP if
necessary), and only do REGFREE if specified (or when the ActGrp ends, of
course):


H bnddir('QC2LE')

D intotest s 256
D inpattern s 256

d regexp pr 10i 0 extproc('regexp')
d xtotest * value options(*string)
d xpattern * value options(*string)
d regfree 10i 0 options(*nopass)

d xreturn s 10i 0
d totest s like(intotest)
d totestptr s * inz(%addr(totest))
d pattern s like(inpattern)
d patternptr s * inz(%addr(pattern))

d cnull c x'00'
d REGFREE c 0


/free

intotest = 'myname@xxxxxxxxxxxxxxxx';
inpattern = '\w+@\w+\.\w{2,3}$';

totest = %trim(intotest);
pattern = %trim(inpattern);

xreturn = regexp (totestptr: patternptr: REGFREE);

dsply xreturn;

*inlr = *on;

/end-free


Just a thought (or two)

Rory

p.s. I still really like it. Don't think that these are all negatives - just
observations...

On Fri, Aug 13, 2010 at 3:56 AM, John McKay <jmckay@xxxxxxxxxxxxxxxx> wrote:

Hi Dennis,

Thanks for your comments.

I had three objectives for producing this implementation.

The first objective was to use a single call instead of REGCOMP, REGEXEC
and REGFREE.. This is closer to the "standard" implementation found in
other
languages and scripts. It also makes regular expressions more accessible
to
those who are unfamiliar with the IBM api's.

My second objective was to remove the confusion / ambiguity caused by
differing character sets / ccsid's. While I cannot guarantee that my
implementation will work successfully across all the character sets /
ccsid's, it is more robust than the IBM-supplied api's.

My third objective was to widen the range of regular expressions
available here. Allied to this was the need to improve the documentation
for RPG developers.

Two of the examples illustrate a return position rather than 1 (alpha, h
and alp25a, \d, both of which return position 4).

Messages which can be of help in determining whether a regular
expression is valid or not can be obtained from the return code. A
negative
return code (range -1 to -18) will indicate the message based on the IBM
documentation. These return codes are in the readme, which can be viewed
on
line.

I agree with you in that "the hard part is in coming up with the right
expression". This is the case in all implementations of regular
expressions. Different implementations use different (albeit very similar)
syntaxes and there is a set of standard escape characters and punctuation
characters.

I had considered an implementation of REGEXEC on its own, but this
cannot be done without a related implementation of REGCOMP. If you think
this to be useful, I will look at it again.


Regards,
John McKay mba

--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.