title: Efficient regex to insert missing apostrophes?
body: <p>I'm trying to build a regular expression and replacement string that I can use to insert missing apostrophes. Examples:</p>
  <blockquote>
  <p>Dont -&gt; Don't</p>
  <p>Ill -&gt; I'll</p>
  </blockquote>
  <p>I can get this working with capture groups, but I'm trying to only have to call .Replace one time. Right now I have something like:</p>
  <pre><code>$apostropheregex = '\b((didn|won|ain|don)(t)|(i)(ll|m))\b'
  $apostrophereplacement='$2$4''$3$5'
  </code></pre>
  <p>But it feels ugly to be mashing together both prefix groups and both postfix groups with the assumption that we only matched one or the other (either a &quot;ll&quot; or a &quot;t&quot; match)</p>
  <p>Does anyone have any suggestions? Is there a better way to approach this problem? Should I indeed treat these as two separate scenarios and run replace twice with separate regexes and replacement strings?</p>
  <p>Update: To clarify, I'm aware that this could have unintended consequences, replacing strings that shouldn't be replaced since English grammatical context is not considered. I'm running this manually after reviewing strings first and I still think this is an interesting question.</p>