title: Replace single quotes with double with exclusion of some elements
body: <p>I want to replace all single quotes in the string with double with the exception of occurrences such as "n't", "'ll", "'m" etc.</p>
  
  <pre><code>input="the stackoverflow don\'t said, \'hey what\'"
  output="the stackoverflow don\'t said, \"hey what\""
  </code></pre>
  
  <p>Code 1:(@<a href="https://stackoverflow.com/users/918959/antti-haapala">https://stackoverflow.com/users/918959/antti-haapala</a>)</p>
  
  <pre><code>def convert_regex(text): 
       return re.sub(r"(?&lt;!\w)'(?!\w)|(?&lt;!\w)'(?=\w)|(?&lt;=\w)'(?!\w)", '"', text)
  </code></pre>
  
  <p>There are 3 cases: ' is NOT preceded and is NOT followed by a alphanumeric character; or is not preceded, but followed by an alphanumeric character; or is preceded and not followed by an alphanumeric character.</p>
  
  <p>Issue: That doesn't work on words that end in an apostrophe, i.e. 
  most possessive plurals, and it also doesn't work on informal 
  abbreviations that start with an apostrophe.</p>
  
  <p>Code 2:(@<a href="https://stackoverflow.com/users/953482/kevin">https://stackoverflow.com/users/953482/kevin</a>)</p>
  
  <pre><code>def convert_text_func(s):
      c = "_" #placeholder character. Must NOT appear in the string.
      assert c not in s
      protected = {word: word.replace("'", c) for word in ["don't", "it'll", "I'm"]}
      for k,v in protected.iteritems():
          s = s.replace(k,v)
      s = s.replace("'", '"')
      for k,v in protected.iteritems():
          s = s.replace(v,k)
      return s
  </code></pre>
  
  <p>Too large set of words to specify, as how can one specify persons' etc.
  Please help.</p>
  
  <p><strong>Edit 1:</strong>
   I am using @anubhava's brillant answer. I am facing this issue. Sometimes, there language translations which the approach fail. 
  Code=</p>
  
  <pre><code>text=re.sub(r"(?&lt;!s)'(?!(?:t|ll|e?m|s|d|ve|re|clock)\b)", '"', text)
  </code></pre>
  
  <p>Problem:</p>
  
  <p>In text, 'Kumbh melas' melas is a Hindi to English translation not plural possessive nouns.</p>
  
  <pre><code>Input="Similar to the 'Kumbh melas', celebrated by the banks of the holy rivers of India,"
  Output=Similar to the "Kumbh melas', celebrated by the banks of the holy rivers of India,
  Expected Output=Similar to the "Kumbh melas", celebrated by the banks of the holy rivers of India,
  </code></pre>
  
  <p>I am looking maybe to add a condition that somehow fixes it. Human-level intervention is the last option.</p>
  
  <p><strong>Edit 2:</strong>
  Naive and long approach to fix:</p>
  
  <pre><code>def replace_translations(text):
      d = enchant.Dict("en_US")
      words=tokenize_words(text)
      punctuations=[x for x in string.punctuation]
      for i,word in enumerate(words):
          print i,word
          if(i!=len(words) and word not in punctuations and d.check(word)==False and words[i+1]=="'"):
              text=text.replace(words[i]+words[i+1],words[i]+"\"")
      return text
  </code></pre>
  
  <p>Are there any corner cases I am missing or are there any better approaches?</p>