On Tue, 2002-05-28 at 16:56, Dan Harrington wrote:
> Greetings everyone,
> I'm trying to do some regexp magic and just can't seem to
> get it done with PHP.
> Basically I want to evaluate a word and if the last character
> of the word is an 's', to knock it off, unless there are 
> two consecutives at the end of the word.
> So 'boys' would become 'boy' 
> and 'cars' would become 'car'
> However, I don't want 
> 'happiness' to become 'happines', so I need to stop
> it where there are two consecutive 'ss' on the end of the word.
> $out=eregi_replace("[s]$",'',$in); will knock off the last one.
> I thought about:
> $out=eregi_replace("[^s][s]$",'',$in);
> but that won't work....
> any ideas?
> thanks

This does what you asked for, but that might not be what you 
really want...since the output from the following is:

This is a block of spooges about 
happiness. Glasses won't work.

Thi i a block of spooge about 
happiness. Glasse won't work.

...which doesn't make a hell of a lot of sense. :) Hope this helps


$text = '
This is a block of spooges about 
happiness. Glasses won\'t work.';

echo "$text\n";

$newtext = preg_replace('/([^s]{1})s{1}\b/is', '$1', $text);

echo "$newtext\n";


 Torben Wilson <[EMAIL PROTECTED]>

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to