It's difficult to describe because I'm not an expert with regular expressions. So I tell you my case.
In HTML want to contribute class
attributes into different data-xyz
attributes. The problem is to get always all classes per match. For example the following HTML:
<span class="note-123 index-3 green">Hello</span> <span class="index-456 red">World<span>
Until now my regular expression is /<span class="([^\"\s]*)\s*/
and it matches the first class. In this case note-123
and index-456
But if I want to get all classes per element I could use /<span class="([^\"\s]*)\s*([^\"\s]*)\s*([^\"\s]*)\s*/
. That works until three classes and the result for the second class return index-456
, red
and an empty string.
Is there a possibility to always get all classes per match no matter how many classes there are? Similar to a nested loop in Javascript?
I would be pleased to get any help from you guys.