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




Ooops... I have to correct one thing in my last post. You also have to treat { and } differently in a BASIC regular expression. They need to bre preceded by backslashes. So, if you want to use REG_BASIC, your pattern has to look like this:

^[A-Z0-9._%-][A-Z0-9._%-]*@[A-Z0-9.-][A-Z0-9.-]*\.[A-Z]\{2,4\}$

I had forgotten about the backslashes in my previous post.

With an extended RE, you don't need to add the backslashes, and your original pattern should work just fine. Clearly, that pattern was intended to be an extended expression.

For more info on RE's, see the following page:
http://en.wikipedia.org/wiki/Regular_expression

The "Syntax" section has some info on the differences between basic and extended regular expressions.


On Wed, 28 Jun 2006, Scott Klement wrote:


[SNIP]
// From: http://www.regular-expressions.info/email.html
RegPattern = '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';
rc = regcomp(reg: %trimr(RegPattern): REG_BASIC+REG_ICASE+REG_NOSUB);
// Why won't this work?!?
Chr256 = 'test@xxxxxxxxxxx';
rc = regexec(reg: %trim(Chr256): 0: match: 0);
[SNIP]

The problem is the plus symbol. On the iSeries (I don't know about elsewhere?) the + symbol is only supported in extended regular expressions, it's not supported in basic ones.

What the + symbol does is match "one or more" of the preceding character. This is in contrast to the * (asterisk) symbol which matches "zero or more" of the preceding symbol.

So if you had a pattern of [A-Z]+ (in an environment that supports the plus symbol) it'll match one or more of the letters from A-Z. Or, slightly more complicated (in your example) you have [A-Z0-9._%-]+, which will match one or more of any letter, any number, a dot, a percent symbol, or a dash.

If you change it to [A-Z0-9._%-]* it'll match zero or more -- which means that it could omit those characters entirely. Whereas with a +, there has to be at least one.

Since the iSeries doesn't support the + operator, you could achieve the same results by changing your pattern to look like this:

^[A-Z0-9._%-][A-Z0-9._%-]*@[A-Z0-9.-][A-Z0-9.-]*\.[A-Z]{2,4}$

All I did was repeat the bracketed expressions, and change the + to a *. Now it has to match one character. Followed by zero or more characters. That'd have the same effect as the original expression you posted, and would work on the iSeries as a basic expression.

The other alternative is to compile your expression as an EXTENDED regular expression instead of a BASIC one. Extended expressions DO support the plus symbol, and therefore your original expression should work fine. To make it extended, change REG_BASIC to REG_EXTENDED on the call to regcomp().

I hope my explanation makes sense, I was struggling to find the right words!

---
Scott Klement  http://www.scottklement.com



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.