Regular Expression to replace dot with space before parentheses
<p>I am working on some customer comments that some of them did not follow grammatical rules. For Example <code>(Such as s and b.)</code> in the following text that provides more explanation for previous sentence is surrounded by two dots. </p>

<pre><code>   text = "I was initially scared of ANY drug after my experience. But about a year later I tried. (Such as s and b.). I had a very bad reaction to this."
</code></pre>

<p>First, I want to find <code>. (Such as s and b.).</code> and then  replace the  dot before <code>(Such as s and b.)</code> to space. This is my code, but it does not work. </p>

<pre><code>text = re.sub (r'(\.)(\s+?\(.+\)\s*\.)', r' \2 ', text )
</code></pre>

<p>Output should be: </p>

<pre><code> "I was initially scared of ANY drug after my experience. But about a year later I tried  (Such as s and b.). I had a very bad reaction to this."
</code></pre>

<p>I am using python.</p>

<p>I would suggest this to remove a dot before parentheses when there is another one following them:</p>

<pre><code>text = re.sub(r'\.(\s*?\([^)]*\)\s*\.)', r'\1', text)
</code></pre>

<p>See it run on <a href="https://repl.it/DrvM/3" rel="nofollow">repl.it</a></p>

python regex