I'm reading some files and I need to remove all the apostrophes in the strings except the ones in words ending with 's.
Frank's blue car -> Frank's blue car
Frank 'blue' car -> Frank blue car
'Frank's blue car -> Frank's blue car
Frank's' blue 'car -> Frank's blue car
'Frank blue car' -> Frank blue car
Frank'blue'car -> Frankbluecar
Thanks in advance for your help!
EDIT: Modified question since I just need the words ending with 's to keep the apostrophe and not only the singular possessive ones.
So basically you want to disallow apostrophes that aren't surrounded by letters on both sides. You can try the following:
Replace anything that matches that with an empty string.
If you want to allow some contractions also, you can replace the s above with another [a-z]. Note that this will also block things like 'tis and 'twas, though.
Note, also, that without an English dictionary database, it will be impossible to distinguish between singular-possessive and contractions ending in S such as "he's" and "it's".
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki