Welcome! Log In Create A New Profile

Advanced

Regular Expression problem.

Posted by BLS 
BLS
Regular Expression problem.
October 19, 2008 11:38AM
Hi I've a regex / MatchRegularExpression() problem, hope you can help.

server is string = "ReferralServer: whois://whois.ripe.net:43"
m1,m2,m3 are strings
//"
IF MatchRegularExpression(server," ( [ReferralServer: whois://]{1,1} ) ( [a-zA-Z]+... 
[.][-a-zA-Z0-9]+ [.] [a-zA-Z]+ ) ( [:][0-9]* ) ", m1,m3,m3) THEN
	Trace(m1 + TAB + m2 + TAB + m3)
ELSE
	Trace("RegEx Error")
END

What I expect is
m1 = "ReferralServer: whois://"
m2= "whois.ripe.net"
m3 = ":43"
Instead I get "RegEx Error". What's my mistake ?

Please note the portnumber, in this case :43, is optional !! Means not every string server contains a portinformation..

thanks in advance !
Bjoern
Fabrice Harari
Re: Regular Expression problem.
October 19, 2008 03:24PM
Hi Bjoern...

This one seems tp be doing what you want:

(ReferralServer: whois://)([ a-zA-Z]*.[ a-zA-Z]*.[ a-zA-Z]*)(:[0-9]*)

and to find it, as I'm sure you'll prefer to know how I did it, I used the regular expression testing utility I wrote a few years back and available on this page:

[fabriceharari.com]

It allows you to test regular expression for inputmask, extraction, and so on... So when you don't plan to become a regular expression guru and still needs them from time to time, it's a great tool

Best regards

Fabrice Harari
WinDev, WebDev, WinDev Mobile consulting
Fabrice Harari
Re: Regular Expression problem.
October 19, 2008 03:54PM
Hi Bjoern

it seems that my previous post didn't make it... So here it goes again...

I think that this expression matches your need:
(ReferralServer: whois://)([ a-zA-Z]*.[ a-zA-Z]*.[ a-zA-Z]*)(:[0-9]*)

I found it by testing using my regular expression utility available here:
http://fabriceharari.com/windev/windev_regularexpressions.htm

If you need to test/debug a regular expression, I find it a great tool, when like me you are not a regular expression guru

Best regards

Fabrice Harari
WinDev, WebDev, WinDev Mobile consulting
BLS
Re: Regular Expression problem.
October 19, 2008 05:16PM
Hi Fabrice,
seems you share the joy of sunday afternoon programming smiling smiley
Yep, you're right, the [.] is nonsense ! later more
Unfortunately your regex don't work.

I think a single dot . should be described as backslash dot. \.
( See : WD expression régulière / Example didactique)

Another problem is due to the fact that in :
ReferralServer: whois://whois.ripe.net:43

the port (:43) is optional. Means some whois server are offering this info, some of them not.

So here I think the regex should be :
( (:[0-9]*)? ) or even better ( (:[0-9]{2,2}) ? )

Now the ? is undocumented but nevertheless in use . WD ex. reg. sample.
The ? means 0 or 1 time.

However still can get it to work sad smiley maybe nesting f.i. (()) is not supported )

I miss some features in WINDEV s MatchRegularExpression()

like ^ from begin , $ from end, as well as | optional... May be I write my own regex engine.in D....will see.

Thanks
Björn

BLS
Re: Regular Expression problem.
October 19, 2008 05:53PM
Hi Fabrice, strange, I've recompiled my mini app. using your regex. and now it works !
thanks again, björn (Time to play with the regex ..)
BLS
Re: Regular Expression problem. Solution
October 19, 2008 06:27PM
Hi Fabrice,
That was indeed a nasty problem. I've copied and pasted a string into the code editor.
This string contains a dead character. ouch!

.
I've learned 3 things.
1 You can use the ? for regex. ? means 0 or 1 expression
2 You can use {2, } means at least 2 expressions
both used here :
(:[0-9]{2,}?)

3 You better don't trust the online help... the regex section needs an update, wrong explaination, buggy source examples

Anyway, finally here the complete and clean source : enjoy

server is string = "ReferralServer: whois://whois.ripe.net:43"

IF MatchRegularExpression(server, ...
	"(ReferralServer: whois://)([-a-zA-Z0-9_]*.[-a-zA-Z0-9_]*.[a-zA-Z]*)(:[0-9]{2,}?)", m1,m2,m3) THEN

	Trace(m1 + TAB + m2 + TAB + m3)
ELSE

	Trace("RegEx Error")
END

Thanks, Björn
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: