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


  • Subject: RE: regcomp/regexec problem
  • From: "Danny Rodius" <danny.rodius@xxxxxxxxx>
  • Date: Thu, 22 Feb 2018 14:32:03 +0100
  • Ironport-phdr: 9a23:owjokhJHpPOLg+NPyNmcpTZWNBhigK39O0sv0rFitYgRLP/xwZ3uMQTl6Ol3ixeRBMOHs6kC07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffwtFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhicZOT438m7Zl8J+gqFUrx29qBJxxJLUbZqJNPpncaPRYc0WSXZDU8tXSidPApm8b4wKD+cZM+pWoZPyp10IrRq+GAKiGOTvxSJJhn/rxq023fkqHAbb0wM6GdIOtnTVoM/vNKcVTO+1zbTIzS7YYvNN2jf86I7IfQ49of2WRr1/b9PcxE8yHA3GllWdsZHpMjea2+gXsWWW7PBsWf+vhmMksQ18rT6izdo2hIbTnIIa0FXE+D18wIYyONK3VlZ2YcWhEJtMryGaMJZ2Qt86T2Fopik6zroGtIa1cicQzpQnwR7eZeaZfoSQ4xLjUvieIStgiX54fL+yiAy+/Eqjx+HmS8W50FVHojBKn9XUs3ACzR3T6syJSvtn+Ueh3C6C2B3J5eFCJ0A1lbDXK4QmwrEtl5oTrF/DEzTtmEX1jK6WcFsr+vSy5+v8fLrqvoWcOJNsigHiLqQundSyAf4gMggBUGWX5fiw2KTn/UDiRbVKj+A5krPDv5DcKsQUuLS1DBNS0oYmuF6DCGLsn+4gsjEfNlVKYhuCionvNBnJJrjkDfr3on6J2DYj87DvBfq9Ws2FJ37P2LbacKx85lVoiUV5hYRF/50IUulEJNr2W0PrvdrXA1kyNAnikMj9D9AonK8XX2SeSpWePKLPqhXAsu4mJe+dIpUStDfgMNA+5O/ogGN/k1JLLvrh5ocedH3tRqcuGE6ee3e52to=
  • List-archive: <https://archive.midrange.com/rpg400-l/>
  • List-help: <mailto:rpg400-l-request@midrange.com?subject=help>
  • List-id: "RPG programming on the IBM i \(AS/400 and iSeries\)" <rpg400-l.midrange.com>
  • List-post: <mailto:rpg400-l@midrange.com>
  • List-subscribe: <https://lists.midrange.com/mailman/listinfo/rpg400-l>, <mailto:rpg400-l-request@midrange.com?subject=subscribe>
  • List-unsubscribe: <https://lists.midrange.com/mailman/options/rpg400-l>, <mailto:rpg400-l-request@midrange.com?subject=unsubscribe>

Hello to all,

Its working now, we should set the locale. Was pointed out by IBM support.

Keep also special attention to the locale is use.

If you use a standard locale like I did, EN_BE, supporting special characters like é à etc... and you want
to check only a thru z, 0 thru 9 then these characters will also been accepted as valid character.

So I create a new locale with and put all these special characters in comment ( % as first character on the line).
The character are defined as of LC_COLLATE

0778.00 LC_COLLATE
0779.00
0780.00 order_start forward;forward
0781.00
0782.00 <NUL> IGNORE;<NUL>
0783.00 <SOH> IGNORE;<SOH>
0917.00 <one-superior> <one>;IGNORE
0918.00 <two-superior> <two>;IGNORE
0919.00 <three-superior> <three>;IGNORE
......
.....
0920.00 <a> <a>;IGNORE
0921.00 %a-acute> <a>;IGNORE
0922.00 %a-grave> <a>;IGNORE
0923.00 %a-circumflex> <a>;IGNORE
0924.00 %a-tilde> <a>;IGNORE
0925.00 %a-diaresis> <a>;IGNORE
0926.00 %a-ring> <a>;IGNORE
0927.00 %ae> <a><e>;IGNORE
0928.00 <b> <b>;IGNORE
0929.00 <c> <c>;IGNORE
0930.00 %c-cedilla> <c>;IGNORE
0931.00 <d> <d>;IGNORE
0932.00 %eth> <d>;IGNORE
0933.00 <e> <e>;IGNORE
0934.00 %e-acute> <e>;IGNORE
0935.00 %e-grave> <e>;IGNORE


You create a new locale only for this purpose. For me I named it EN_BE_REGX

So for info to all the source:

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

/copy z0stlps/qcpysrc,cregexpr

dcl-pr setlocale pointer extproc('_C_PSX_setlocale');
category int(10) value;
localetype pointer value options(*string);
end-pr;

// Main routine

dcl-proc main;
dcl-pi main extpgm('STL9125P');
PxOrderNbr char(8);
PxOK char(1);
end-pi;

dcl-c LC_ALL -1;
dcl-c LOCALETYPE_EN_BE '/QSYS.LIB/QGPL.LIB/EN_BE_REGX.LOCALE';
dcl-s oldLocaleSave varchar(1000);
dcl-s oldLocalePtr pointer;

dcl-s RegPattern varchar(50);

dcl-s RegString varchar(10);
dcl-ds reg likeds(C_regex_t);
dcl-ds pmatch likeds(C_regmatch_t);
dcl-s rc int(10) inz(9);
dcl-s cflags int(10);
dcl-s msg char(20);


// Save actual local and set new local
oldLocalePtr = setlocale (LC_ALL : *NULL);
oldLocaleSave = %str(oldLocalePtr);
// set the locale
setlocale(LC_ALL : LOCALETYPE_EN_BE);
// do the locale-sensitive function

cflags = REG_EXTENDED + REG_NOSUB + REG_ICASE;

RegPattern = '^[A-Z0-9_-]{1,8}$';

rc = regcomp(reg: RegPattern: cflags);

if ( rc = 0);
RegString = %trim(PxOrderNbr);
rc = regexec(reg: RegString: 0: pmatch: 0);
PxOK = %char(rc);
endif;

regfree(reg);

//Set initial local back
setlocale (LC_ALL : oldLocaleSave);
dsply PxOK ' ' msg;
return;

end-proc;

So this program will accept all characters a thru z, A thru Z, 0 thru 9, underscore and hyphen for a length of 1 to 8 characters.
Any special characters like the French using é,à,.. will generate an error.

Hope that someone has use for this information.


-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Danny Rodius
Sent: donderdag 8 februari 2018 17:23
To: 'RPG programming on the IBM i (AS/400 and iSeries)' <rpg400-l@xxxxxxxxxxxx>
Subject: RE: regcomp/regexec problem

Hi Jan,

Call has already been opened.
Will place the result here when solution found or not.

@all, thanks for helping out.

Best regards,
DAnny

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jan Grove Vejlstrup
Sent: donderdag 8 februari 2018 16:06
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: regcomp/regexec problem

I think, it's time for a call to IBM support.

Jan

Am 08.02.2018 um 12:17 schrieb Thomas Raddatz:
Same here. QLOCALE is properly set to "German":

Locale . : /QSYS.LIB/DE_DE.LOCALE

But regexec() still does not work.

Thomas.


-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von
Danny Rodius
Gesendet: Donnerstag, 8. Februar 2018 10:54
An: 'RPG programming on the IBM i (AS/400 and iSeries)'
Betreff: RE: regcomp/regexec problem

Hi Jan,

Initial the problem was created by me.
Could you provide an example of your working pgm?

I ask this because my sysval QLOCALE is correctly set for Belgium /QSYS.LIB/EN_BE.LOCALE. (see previous mails) This is also set on the userprofile that runs the program.
Could you also point to me where in this threat iconv() was mentioned?

Thanks for any help
Danny




-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jan
Grove Vejlstrup
Sent: donderdag 8 februari 2018 10:20
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: regcomp/regexec problem

Hello Thomas,

I use regex to check mail addresses. But it is necessary to set the
system-value QLOCALE to the correct value. I'm living in the
german-speaking part of Switzerland and my value is
/QSYS.LIB/DE_CH.LOCAL

Before that change, I had to use iconv() as mentioned earlier.

Best regards

Jan

Am 07.02.2018 um 21:11 schrieb Tools/400:
Hi Danny,

That is exactly what I am faced with. regcomp() works, but regexec()
fails and I still have no idea why.

Thomas.

Am 07.02.2018 um 13:50 schrieb Danny Rodius:
Hi Thomas,

thanks for this info.
Have included this and now the regcomp is working, but still the
regexec is not working.
We the program with a valid ordernbr and still the regexex returns a 1.

Program source as attachment

Any other ideas.

Already copied a number of examples but none of them seems to work.
Is there something special about this That I'm overlooking?

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
Tools/400
Sent: dinsdag 6 februari 2018 22:43
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: regcomp/regexec problem

It is correct that LOCALETYPE is specific to C/CPP. I assume that I
actually wanted to add the following URL, which describes the usage
of
setLocale():

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

Thomas.

Am 06.02.2018 um 11:53 schrieb Danny Rodius:
Hi all,

Taken some of your remarks into account and this is the followup:

To Carsten,

Have checked this locale stuff and settings QLOCALE =
/QSYS.LIB/EN_BE.LOCALE Job CCSID = 1148 Seems a valid combination.

To David,

Like to follow the regcomp/regexec path instead of the SQL.
But have tried your expression and got now a return code 11. Even
with the extended flag on.

To Thomas,

Maybe I'm missing something but LOCALETYPE(...) seems only to exist
on the compiler command for C/CPP.

General, I'm still searching
Any other ideas

BR+
Danny


-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
Flensburg, Carsten
Sent: maandag 5 februari 2018 15:04
To: RPG programming on the IBM i (AS/400 and iSeries)
<rpg400-l@xxxxxxxxxxxx>
Subject: RE: regcomp/regexec problem

Hi Danny,

A possible explanation can be found here (regcomp() and regexec()
functions are Locale Sensitive):
http://www-01.ibm.com/support/docview.wss?uid=nas8N1010877

Cheers,
Carsten

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
Danny Rodius
Sent: 5. februar 2018 11:42
To: rpg400-l@xxxxxxxxxxxx
Subject: 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?
--
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

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



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

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


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


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.