Re: [SOLVED] Regular expression
| From: | Barry | Date: | Mon, 30 Jan 2006 14:52:27 +0000 |
| Subject: | Re: [SOLVED] Regular expression | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229471@lists.php.net to get a copy of this message | ||
Silvio Porcellana [tradeOver] wrote:
Barry wrote:Nah found a solution ^^ My regular expression is as follows: ereg_replace (",([[:alnum:][:space:]]*)$"," and \\1",$string) Thanks for the help =) Note: that expression does not work with string who have other signs than "," in it e.g. "!" or "?". Barry -- Smileys rule (cX.x)C --o(^_^o)Simple reg help please i want to match the last "," in "a,b,c,d" and replace it with " and "Without using a regexp, you could do: <code> $string = 'a,b,c,d'; $letters = explode(',', $string); $last_letter = array_pop($letters); $final_string = implode(',', $letters) . ' and ' . $last_letter; </code> Not very efficient - but should work... Silvio