Barry wrote:
Simple reg help please
i want to match the last "," in "a,b,c,d" and replace it with " and "
i tried ereg_replace(",([a-zA-z])*$"," and ",$string);
but i forgot how to add the "d" which is also matched now back to the
" and "
Can you give any good reg_exp sites where to learn it?
Its long ago since i used reg exp and i lost the hang of it... :(
btw. any sites that have reg_exp that works witht PHP would be fine.
i know http://www.regular-expressions.info/tutorial.html
But that examples dont work with preg_match and ereg.
Thanks ^_^
Try this:
$pattern= "%,([\w\.]+)$%"; //put any line ending punctuation in the
[]
$replace= " and $1"; //may need $replace= " and " . $1;
$string= preg_replace($pattern, $replace, $string);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php