the use of regular expression
<p>I'm new in regular expression, but I want to match a pattern in about 2 million strings.
There three forms of the origin strings shown as follows:</p>

<pre><code>EC-2A-07&lt;EC-1D-10&gt;
EC-2-07
T1-ZJF-4
</code></pre>

<p>I want to get three parts of substrings besides <code>-</code>, which is to say Iãwant to get <code>EC</code>, <code>2A</code>, <code>07</code>respectively. Especially, for the first string, I just want to divide the part before <code>&lt;</code>.</p>

<p>I have tried <code>.+[\d]\W</code>, but cannot recognize <code>EC-2-07</code>, then I use <code>.split('-')</code> to split the string, and then use index in the returned list to get what I want. But it is low efficient.</p>

<p>Can you figure out a high efficient regular expression to meet my requirements?? Thanks a lot!</p>

<p>You can try this:</p>

<pre><code>^(\w+)-(\w+)-(\w+)(?=\W).*$
</code></pre>

<p><a href="https://regex101.com/r/5D9BeE/1" rel="nofollow">Explanation</a></p>

<p><a href="https://repl.it/EAM9" rel="nofollow">Python Demo</a></p>

python regex string