Page 1 of 1

Hep Needed: Converting EREG function into PREG_MATCH

Posted: Tue Aug 10, 2004 1:02 pm
by Takuma
As stated in the title, I have the following code:

Code: Select all

ereg("^їA-Za-z0-9]+їA-Za-z0-9_]*їA-Za-z0-9]$", $usr)

Code: Select all

ereg("^їA-Za-z]+ї.A-Za-z0-9_]*@їA-Za-z0-9]+ї.A-Za-z0-9]*ї.A-Za-z0-9]?$", $infoї'email'])
I read the PREG_MATCH is quicker than EREG but I figured I dont know anything about Perl Regular Expression thing... Could someone convert it for me? Obviously first code is to validate usernames, second is e-mail. If someone is also able to give me a good website to learn Perl Reg Exp thing please tell me.

Thanks again!

:wink:

Posted: Tue Aug 10, 2004 1:59 pm
by feyd
sure:

Code: Select all

ereg("^[A-Za-z0-9]+[A-Za-z0-9_]*[A-Za-z0-9]$", $usr);

// to

preg_match("#^[A-Z0-9]+[A-Z0-9_]*[A-Z0-9]$#i", $usr);

// and

ereg("^[A-Za-z]+[.A-Za-z0-9_]*@[A-Za-z0-9]+[.A-Za-z0-9]*[.A-Za-z0-9]?$", $info['email']);

// to

preg_match("#^[A-Z]+[.A-Z0-9_]*@[A-Z0-9]+[.A-Z0-9]*[.A-Z0-9]?$#i", $info['email']);

I'd recommend the book: "Mastering Regular Expressions", published by O'Reilly Associates (ISBN 0-596-00289-0)