Delete trailing marks ]]
<p>Doing some regex and I can't sus out how I can get rid of the ]] marks from this string</p>

<p>Regex:</p>

<pre><code>&lt;title&gt;&lt;!\[CDATA\[(.*?)&lt;/title&gt;
</code></pre>

<p>String:</p>

<pre><code>&lt;item&gt;
            &lt;title&gt;&lt;![CDATA[Coronation Street star Jean Alexander dies aged 90]]&gt;&lt;/title&gt;
            &lt;description&gt;
</code></pre>

<p>Returned:
Coronation Street star Jean Alexander dies aged 90]]</p>

<p>What I want returned:
Coronation Street star Jean Alexander dies aged 90</p>

<p>I infer that you'd like an answer with respect to using a regex with python.  So, here's some code that performs the desired action:</p>

<pre><code>import re
string = "&lt;title&gt;&lt;![CDATA[Coronation Street star Jean Alexander dies aged 90]]&gt;&lt;/title&gt;"
result = re.findall(r"\[.*\[(.*?)\]\]", string)
print ' '.join(result) 
</code></pre>

<p>Note: this code runs under python 2.8
May run code <a href="http://www.tutorialspoint.com/execute_python_online.php?PID=0Bw_CjBb95KQMQzAxQ2pfRWxBekU" rel="nofollow">here</a>.</p>

<p>A few points about the code.  The findall method of the regular expression object is available once the code imports that object. Your regex needs a little bit of tweaking in order for the two terminating brackets to not appear by <em>including them in the regex</em>.  Now, the result will be a list with the correct data and that list is then converted by next line of code into a string.</p>

<p>I find it easier personally using PHP for something like this, so I'll also show you a PHP solution that runs on PHP versions 5 and 7:</p>

<pre><code>&lt;?php
$subject = "[CDATA[Coronation Street star Jean Alexander dies aged 90]]";
$pattern = "/\[.*\[(.*?)\]\]/";
preg_match($pattern, $subject, $matches);
var_dump($matches[1]);
</code></pre>

<p>With PHP the result is immediately available as a string in element 1 of $matches as long as preg_match is successful.</p>

<p>See <a href="https://3v4l.org/9NVLl" rel="nofollow">live code</a>.</p>

python regex