Thread: Regex examples
View Single Post
Old 07-26-2025, 08:34 AM   #789
ElMiko
Evangelist
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 462
Karma: 65460
Join Date: Jun 2011
Device: Kindle
I'm trying to insert a character into a string. Specifically, I'm trying to insert omitted apostrophes into contractions. I fear this is impossible with regex since I'm not actually matching anything—I'm matching the non-space between two characters.

The search I've been using is:

Code:
(?<=\b[Cc]an|\b[DdWw]on|\b[CcWw]ouldn|\b[Ss]houldn|[Dd]idn|\b[Ii]sn|\b[Aa]ren|\b[WwHh]asn)t\b
which matches the ending "t" that can then be replaced by "’t". But I'm hoping there's a way to write the search such that I'm functionally inserting the apostrophe rather than replacing the "t".
ElMiko is offline   Reply With Quote