Python Regex and group function
<p>Hi trying to separate each of the expressions from the colon.  So want to obtain 'ss_vv', 'kk' and 'pp'.  But the two print expressions below give me 'v' and 'k', so getting parts only of each string.  Can anyone see what wrong here?       </p>

<pre><code>m0 = re.compile(r'([a-z]|_)+:([a-z]|_)+:([a-z]|_)+')
m1 = m0.search('ss_vv:kk:pp')
print m1.group(1)
print m1.group(2)
</code></pre>

<p>What are the other rules for the regular expression? based on your question, this regex would do:</p>

<pre><code>m0 = re.compile(r'(.*):(.*):(.*)')
m1 = m0.search('ss_vv:kk:pp')
print m1.group(1)
print m1.group(2)
</code></pre>

<p><strong>UPDATE:</strong>
as mentioned by @Jan in the comments, for efficient and better use of regex, you can modify it as </p>

<pre><code>regex = r'([^:]+):([^:]+):([^:]+)'
m0 = re.compile(regex)
</code></pre>

<p>output:</p>

<pre><code>ss_vv
kk
</code></pre>

<p>or by just splitting the string:</p>

<pre><code>string = 'ss_vv:kk:pp'
parts = string.split(':')

print parts

outputs: ['ss_vv', 'kk', 'pp']
</code></pre>

python regex