Page 1 of 1

Regex...yes i know...please at least look once :)

Posted: Mon Aug 04, 2003 7:08 pm
by mikusan
Well i have a piece of code... and my quesition is more of a please help me to improve it as well as it doesn't work!! :lol:

Well it work mostly but i think i have used too much code to do a simple thing...less chat here is the code:

Code: Select all

if( eregi( "^[a-z0-9]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,3}$", $EditedMessage ) )
	{
		$EditedMessage = ereg_replace( "^[a-z0-9]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,3}$", "<a href="mailto:\\0">\\0</a>", $EditedMessage );
	}
	else
	{
		$EditedMessage = ereg_replace("(([^\.<>[]]+\.)|([[]]+://))+". "[^\.<>[]]+\.[^<>[]]+", "<a href="http://\\0" target="_blank">\\0</a>", $EditedMessage);
	}
If you haven't noticed the first reg ex is to theoretically replace emails with the equivalent link to an email...well to make it short that doesn;t work...
the second replaces all types of links to the HTML equivalent ant that works fine...

Do you see a flaw in my logic or statement...is there a better way to do this? Also any ideas why my email recognizer sucks??

Thanks!!

Posted: Mon Aug 04, 2003 7:18 pm
by McGruff
Regex fns (preg_match, preg_replace etc) are apparently slightly faster than posix (ereg).

Try this handy tool for tuning up your regex expressions:

http://www.weitz.de/regex-coach/#install

Posted: Mon Aug 04, 2003 11:30 pm
by m3rajk
someone else was saying it the opposite way when i was asking about regex earlier


but perl has an advantage over posix.... the ability to do non-greedy

also, go to the local bookstore, bring a camera phone (so you don't have to remember or buy the book) and look at the e-mail stuff in orielly's php cook book ;)

Posted: Fri Aug 22, 2003 4:26 pm
by JAM
McGruff wrote:Regex fns (preg_match, preg_replace etc) are apparently slightly faster than posix (ereg).

Try this handy tool for tuning up your regex expressions:

http://www.weitz.de/regex-coach/#install
That application was indeed useful. Thought I'd bump the post. Thank you.