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



Your regular expression lacks a quantity identifier, such as:

* = zero or more matches
+ = one or more matches
? = zero or one match
{5} = Exactly 5 matches
{2,10} = 2 to 10 matches

So probably the correct regular expression that you want to use is:

^[A-Z0-9-_]+$

I added the (+) quantifier to check for one or more characters.

The next problem is that the regular expression functions are locale sensitive.

Quoted from "ILE C/C++ Runtime Library Functions":

"Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE and LC_COLLATE categories of the
current locale. This function is not available when LOCALETYPE(*CLD) is specified on the compilation
command. For more information, see "Understanding CCSIDs and Locales" on page 3-20."

Therefore the fixed regular expression should work for ccsid 37 but may not work for 1141 (German). So far I could not get it working using the setLocale() functions as described here:

http://www-01.ibm.com/support/docview.wss?uid=nas8N1012446

What I do so far is converting the pattern and the string to ccsid 37 before calling regcomp() and regexec().

Thomas.


-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von Danny Rodius
Gesendet: Montag, 5. Februar 2018 11:42
An: rpg400-l@xxxxxxxxxxxx
Betreff: regcomp/regexec problem

Hi,



Want to validate a field with the regular expression support.

Took a look at the example in "Who Knew You Could Do That with RPG IV"
redbook and wrote the following code:



ctl-opt main(main) dftactgrp(*no);

/copy cregexpr

dcl-proc main;

dcl-pi main extpgm('STL9120P');

PxOrderNbr char(8);

PxOK char(1);

end-pi;



dcl-s RegPattern varchar(50);

dcl-ds preg likeds(C_regex_t);

dcl-ds pmatch likeds(C_regmatch_t) dim(1);

dcl-s rc int(10) inz(9);

dcl-s cflags int(10);



cflags = REG_EXTENDED + REG_ICASE;

RegPattern = '^[A-Z0-9-_]$';

rc = regcomp(preg: RegPattern: cflags);

if ( rc = 0);

rc = regexec( preg: %trim(PxOrderNbr): %elem(pmatch): pmatch: 0);

PxOK = %char(rc);

endif;

regfree(preg);

return;

end-proc;



When calling with first parm = '12345678' it return allways 1 (not equal).



The regexec seems not to work. So what I'm doing wrong, where I have failed?

Anyone already used the regcomp/regexec combination to test a field?

Know that I can do it with SQL but want to have it in plain RPG.



Anyone







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

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD
--
IMPORTANT NOTICE:
This email is confidential, may be legally privileged, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone else is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.