
January 28th, 2009, 07:11 PM
|
|
|
|
Preg_replace regex to replace "rogue" apostrophes
Hi,
Following up on a previous question posted to the wrong forum...
I want to search for any "rogue" apostrophes in a long $string that don't match common usage, and replace them with a space.
For example. they're, I've, he'll will remain as-is. But with... they'vve, he'lele, big'ss the ' will be replaced by a space and effectively split the word in two within the string.
This is the regex I've got which seems to find the matches ok, I just don't know how to get it replacing unwanted apostrophes.
Can anyone help? Thanks, Regan.
Code:
$word = "they'll";
if ( preg_match("/([A-Za-z0-9]+)(\')(s|t|d|ll|re|ve|m)( |$)/i",$word,$matches) ) {
die($matches[0]);
}
die('nomatch');
r
Last edited by ryel01 : January 28th, 2009 at 07:19 PM.
|