Re: Regular expression
| From: | Al | Date: | Mon, 30 Jan 2006 15:43:17 +0000 |
| Subject: | Re: Regular expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229476@lists.php.net to get a copy of this message | ||
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);