I have made a regex in php to find the tag and the attributes in an html line. It works but only works on the first attribute instead of repeating. The follow code gets me the first attribute and value.
'@<barcode(\s([a-z]+)="([^"]+)").*/>@m'
So then I added the plus to make it repeat, but it won't work.
'@<barcode(\s([a-z]+)="([^"]+)")+.*/>@m'
What happens after adding the plus is that it only selects the last attribute and value.
I just need all the attributes and values in an array, so I am wondering what I am doing wrong. Here is the possible html that I am searching through. Sometimes attribute are not always needed so I have to take that into account.
<barcode type="C128B" height="10" fontsize="0.4" code="testcode" align="L"/>
<barcode type="Hello"/>
<barcode type="Hello" code="balls"/>
<barcode type="C128B" height="10" fontsize="0.7" code="test" align="L"/>
I have an example on regex101 to see the problem https://regex101.com/r/jMdA6S/1
Our current application works, but only by repeating the following lines
'@<barcode ([a-z]+)="(.*)" ([a-z]+)="(.*)" ([a-z]+)="(.*)" ([a-z]+)="(.*)" ([a-z]+)="(.*)".*/>@m'
Which means everytime I add a new attribute I have to add another block of code in the regex. I am trying to avoid this as we sometimes have to add a new attribute to add different features.