I want to match HTML tags and its containing attributes. Tried the following regex:
/<(\w+)(?: +(\w+)="[\w,;.:\-#'+~*?=&%\$!\/'\]\[@\(\)\s]*")*/gm
On that input:
<p><li first="1" second="2" third="3"></li><b><br/><p><li first="1" second="2" third="3"></li><b><br/></p>
<p><li first="1" second="2"></li><b><br/><p><li first="1" second="2"></li><b><br/></p>
<p><li first="1"></li><b><br/><p><li first="1"></li><b><br/></p>
I only get one attribute. If there are more than one attributes in a tag, I always get the last one. First row returns third
, second row returns second
and last row returns first
for group 2
.
The result is for line number one is:
p li third b br p li third b br
But should be:
p li first second third b br p li first second third b br
How do I get all attributes to a tag?