Assist with re Module
<p>I need to extract all those strings between the patterns nr: or /nr:. Can anyone please help me?</p>

<p>The string is </p>

<pre><code>nr:Organization/nr:Customer/nr:Agreement/nr:date/nr:coverage/nr:Premium/nr:Option/nr:OptionID
</code></pre>

<p>Output I am expecting is</p>

<pre><code>Organization, Customer, Agreement,...OptionID
</code></pre>

<p>Here is a way with regular expression and split:</p>

<pre><code>import re

string = 'nr:Organization/nr:Customer/nr:Agreement/nr:date/nr:coverage/nr:Premium/nr:Option/nr:OptionID'

x = filter(None, re.split('/*nr:', string))
print x
</code></pre>

<p>The regular expression looks for <code>nr:</code> preceded (or not) by a '/'. Since the <code>re.split</code> function would leave some empty elements, applying a <code>filter</code> to it, will give you the desired output.</p>

<p>Also see it in action here: <a href="https://eval.in/656744" rel="nofollow">https://eval.in/656744</a></p>

python