regex - HTML tags with parameters
<pre><code>import re
text = "sometext &lt;table var1=1 var2=2 var3=3&gt; sometext"
tokenize = re.compile(r'(&lt;\w+) ((\w+=\w+ )*) (\w+=\w+&gt;)')
tokens = tokenize.search(text)
</code></pre>

<p>What I'm attempting to do here, in an exercise to better understand how to use regular expressions in Python, is write one to split HTML tags which have params into constituent parts so I can reformat these. tokens.groups() produces:</p>

<pre><code>('&lt;table', 'var1=1 var2=2 ', 'var2=2 ', 'var3=3&gt;') 
</code></pre>

<p>but what I'm hoping to see is:</p>

<pre><code>('table' 'var1=1', 'var2=2', 'var3=3') 
</code></pre>

<p>so I want the open, close '&lt;', '>' to not feature, and first and second params (and additional ones up to the last) to be recognised as separate tokens. Where am I going wrong?</p>

<p>Thanks!</p>

<p>I think some easier regex and a split is better for this case.</p>

<pre><code>import re
text = "sometext &lt;table var1=1 var2=2 var3=3&gt; sometext"
print(re.findall("&lt;(.+)&gt;", text)[0].split())
</code></pre>

<p>Returns <code>['table', 'var1=1', 'var2=2', 'var3=3']</code></p>

python regex