title: Merging three regex patterns used for text cleaning to improve efficiency
body: <p>Given a text I want to make some modifications:</p>
  <ol>
  <li>replace uppercase chars at the beginning of a sentence.</li>
  <li>remove chars like <code>’</code> or <code>'</code> (without adding whitespace)</li>
  <li>remove unwanted chars for example <code>³</code> or <code>?</code> <code>,</code> <code>!</code> <code>.</code> (and replace with whitespace)</li>
  </ol>
  
  <pre><code>def multiple_replace(text):
      # first sub so words like can't will change to cant and not can t
      first_strip=re.sub(&quot;[’']&quot;,'',text) 
      def cap(match):
          return (match.group().lower())
  
      p = re.compile(r'((?&lt;=[\.\?!]\s)(\w+)|(^\w+))')
      #second sub to change all words that begin a sentence to lowercase
      second_strip = p.sub(cap,first_strip) 
      # third_strip is to remove all . from text unless they are used in decimal numbers
      third_strip= re.sub(r'(?&lt;!\d)\.|\.(?!\d)','',second_strip)
      # fourth strip to remove unexpected char that might be in text for example !,?³ and replace with whitespace
      forth_strip=re.sub('[^A-Za-z0-9@#_$&amp;%]+',' ', third_strip)
      return forth_strip
  </code></pre>
  <p>I am  wondering if there is a more efficient way of doing it? Because I am  going over the text 4 times just so it can be in the right format for me to parse. This seems a lot especially if there are millions of documents. Is there a more efficient way of doing this?</p>