Delete string in between special characters in python
<p>I have string something like this</p>

<pre><code>mystring = "CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\n*options; mprint ls=max mprint;\n\n****************************************out; asd; ***hg;"
</code></pre>

<p>I want to delete the string between * and ;
output should be</p>

<pre><code>"CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\ mprint ls=max mprint;\n\n asd;"
</code></pre>

<p>I have tried this code</p>

<pre><code>re.sub(r'[\*]*[a-z]*;', '', mystring)
</code></pre>

<p>But it's not working.</p>

<p>You may use</p>

<pre><code>re.sub(r'\*[^;]*;', '', mystring)
</code></pre>

<p>See the <a href="https://ideone.com/Sq2jWS" rel="nofollow">Python demo</a>:</p>

<pre><code>import re
mystring = "CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\n*options; mprint ls=max mprint;\n\n****************************************out; asd; ***hg;"
r = re.sub(r'\*[^;]*;', '', mystring)
print(r)
</code></pre>

<p>Output:</p>

<pre><code>CBS Network Radio Panel;
title2 New York OCT13W4, Panel Weighting;
 mprint ls=max mprint;

 asd;
</code></pre>

<p>The <code>r'\*[^;]*;'</code> pattern matches a literal <code>*</code>, followed with zero or more characters other than <code>;</code> and then a <code>;</code>.</p>

python regex