How to use multiple token using Regex Expression
<p>To extract first three letters 'abc' and three sets of three-digits numbers in <code>000_111_222</code> I am using the following expression:</p>

<pre><code>text = 'abc_000_111_222'
print re.findall('^[a-z]{3}_[0-9]{3}_[0-9]{3}_[0-9]{3}', text)
</code></pre>

<p>But the expression returns empty list when instead of underscores there are minuses or periods used instead: <code>abc.000.111.222</code> or <code>abc-000-111-222</code> or any combination of it like: <code>abc_000.111-222</code></p>

<p>Sure I could use a simple replace method to unify the text variable <code>text=text.replace('-','_').replace('.','_')</code></p>

<p>But I wonder if instead of replacing I could modify regex expression that would recognize the underscores, minuses and periods.</p>

<p>Why not abandon <code>regexes</code> altogether, and use a clearer and simpler solution?</p>

<pre><code>$ cat /tmp/tmp.py
SEP = '_.,;-=+'

def split_str(text):
    for s in list(SEP):
        res = text.split(s)
        if len(res) &gt; 1:
            return text.split(s)

print(split_str('abc_000_111_222'))
print(split_str('abc;000;111;222'))
print(split_str('abc.000.111.222'))
print(split_str('abc-000-111-222'))
</code></pre>

<p>Which gives:</p>

<pre><code>$ python3 /tmp/tmp.py
['abc', '000', '111', '222']
['abc', '000', '111', '222']
['abc', '000', '111', '222']
['abc', '000', '111', '222']

$
</code></pre>

python regex