Regex don't function correctly?

243 views
Skip to first unread message

Victor Casajuana Mas

unread,
Jun 5, 2019, 3:53:52 AM6/5/19
to Harbour Users
Hi Group.

I'm testing regex functions in Harbour 3.2 but I think that don't function correctly.

This is My Prg:

FUNCTION Main()

LOCAL cVar := "pru...@correo.com"
LOCAL cRegex := "/[A-Z0-9._%+-]+@[A-Z0-9-]+.+.[A-Z]{2,4}/"
LOCAL pRegex := hb_RegExComp( cRegex,.T.,.T. )

?lIsReges:=hb_IsRegex(pRegex)
aArr:=hb_RegEx(pRegex,cVar,.T.,.T.)
?lLike:=hb_RegExLike( pRegEx, cVar,.T.,.T. )
?lHas:=hb_RegExHas( pRegEx, cVar,.T.,.T. )

RETURN NIL

This is the result (array is empty):


2019-06-05_09h43_17.png


The regex string is a validate email


In other web's to test regex works correctly:

2019-06-05_09h46_50.png





AL67

unread,
Jun 5, 2019, 7:10:31 AM6/5/19
to Harbour Users

Hi!


LOCAL cRegex := "/[A-Z0-9._%+-]+@[A-Z0-9-]+.+.[A-Z]{2,4}/"

In Harbour regular expression not begin and ending with /
and member dot is special character match any character


---
Adam

Victor Casajuana Mas

unread,
Jun 5, 2019, 4:18:23 PM6/5/19
to Harbour Users
Thanks Adam.
So with Harbor, do you have to modify the standard regex expressions to work correctly?
Where can I see information about it?
Thank you.

Victor Casajuana Mas

unread,
Jun 5, 2019, 4:21:50 PM6/5/19
to Harbour Users
Excuse me, the correct regex for email is:
^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$
It's works correctly in Harbour.
Thanks!!!

Antonino Perricone

unread,
Jun 6, 2019, 3:23:09 AM6/6/19
to Harbour Users
On Wednesday, June 5, 2019 at 10:18:23 PM UTC+2, Victor Casajuana Mas wrote:
So with Harbor, do you have to modify the standard regex expressions to work correctly?
No, the regex between / is a javascript syntax only. 
The official email regex is https://emailregex.com/ 

Victor Casajuana Mas

unread,
Jun 6, 2019, 3:32:51 AM6/6/19
to Harbour Users
Thanks for the answer Antonino.

Reply all
Reply to author
Forward
0 new messages