On Tuesday 10 March 2009 15:44, David Villalobos Cambronero wrote:
> 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 = "f...@bar" 

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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to