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



Why do you need the expression in the string. Is regexpsrv a UDF? that
calls a service program that hides expression code? If yes, then you debug
your function. You have to use two sessions.STRDBG in one and issue a
SBREAK to cause the service program to stop and then switch to another
session and start debug to step through the code.

On Wed, Mar 28, 2012 at 4:54 PM, Monnier, Gary <Gary.Monnier@xxxxxxxxx>wrote:

Tom,

I suggest pulling your REGEXEC stuff into a test program. You don't
mention any error code being returned so I'd include regerror() in my test
program. It can be a life saver.

The test program will allow you to play with the pattern until you find
what you want.

You can also look at
http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorialthey have a phone number matching pattern of \b\d{3}-\d{4}.

Theirs \b\d{3}-\d{4}
Yours \d{3}-\d{4}

Maybe all you are missing is the \b?

HTH,

Gary Monnier

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:
midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Thomas Garvey
Sent: Wednesday, March 28, 2012 3:31 PM
To: 'Midrange Systems Technical Discussion'
Subject: Anybody experienced with regular expressions and UDFs?

Hi,

I'm trying to develop a User Defined Function that will test a given value
against a regular expression pattern. I've found code online by Scott
Klement that utilizes the regcomp (Compile Regular Expression) and regexec
(Execute Compiled Regular Expression) APIs. I've put this into an RPGLE
module and created a service program, then registered the UDF using the
CREATE FUNCTION command in SQL. Then I use the scalar function to test
values in a character field of a table.

For example...

SELECT str
FROM strTable
WHERE regexpsrv(str, '\d{3}-\d{4}') = 1

The function gets passed the test value (str), and the regular expression
pattern (inside the single quotes), and a value of 0 or 1 is returned (1 if
the test value contains the regular expression pattern, 0 if not).

The problem is, it ALWAYS returns a zero. My test database has values
that should sometimes return a zero, but mostly a 1. Incidentally, the
regular expression essentially is looking for 3 digits, followed by a dash,
followed by 4 digits (a phone number of the form xxx-xxxx).

I can put the thing in debug and the expression is compiled and returns a
zero for the result of the regcomp call. But the call to regexec just
always returns a zero, as in 'it doesn't match. The thing is, I can go to
a Regular Expression test site (
http://www.regular-expressions.info/javascriptexample.html), which allows
me to essentially do the same thing (enter a test value and an expression)
to test the expression against various values. It tells me the correct
results based on the sample data I have. MY UDF just rejects everything.

If anyone can point me in a direction, or tell me what I'm doing wrong,
I'd appreciate it very much.

Thanks in advance,

Thomas Garvey

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-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.