[Gambas-user] Help using gb.pcre

David Villalobos Cambronero david_villalobos_c at ...43...
Tue Mar 10 22:50:38 CET 2009


Many thanks, maybe a little example in the wiki could help.

 Regards


--
David



----- Original Message ----
From: Rob <sourceforge-raindog2 at ...94...>
To: gambas-user at lists.sourceforge.net
Sent: Tuesday, March 10, 2009 2:53:08 PM
Subject: Re: [Gambas-user] Help using gb.pcre

On Tuesday 10 March 2009 15:44, David Villalobos Cambronero w
> Hi, I need to match some regular expresions, I think I can use Gambas to
> do it, in the documentation says somethig like this:
> (?i)\b[a-z0-9._%\-]+@[a-z0-9._%\-]+\.[A-Z]{2,4}\b
> But how can I use it, any idea?

That regular expression is meant to extract a valid email address.  (It may 
not be a working email address, but it should at least be legal.)

One thing I should probably make clearer in the documentation is that due 
to the way Gambas uses character constants like \n, you need to double up 
on backslashes when you're specifying a regular expression as a constant.  
So if the user is entering it or you're reading it from a file, it might 
be a\s+(b\S+) but if you're hardcoding it into your program it needs to 
be "a\\s+(b\\S+)".  Here is a Gambas script to demonstrate (just tried it 
in my own console and it runs in 2.9, but watch out for my email client's 
word wrap.)

USE "gb.pcre"

DIM myemail AS String
DIM validemail AS String
DIM re AS RegExp

myemail = "foo at ...2101..." 

re = new RegExp(myemail, "(?i)\\b[a-z0-9\\._%\\-]+@[a-z0-9._%\\-]+\\.[A-Z]
{2,4}\\b")
validemail = re.Text
if not validemail then
        print myemail & " is not a legal email address.\n"
else
        print myemail & "\n"
end if

Rob

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user



      




More information about the User mailing list