I am trying to find all occurrences (there could be zero or more) of anchor(<a>
) HTML tags with specific attributes/text (to be captured as groups). But the groups (attributes) can occur in any order.
Regex for fixed order that works fine:
<a\s+.*attr1="myattr".*attr2="(.+)".*attr3="(.+)".*>(.+)</a>
Tried the following regex for different order without success:
<a\s+.*?((attr1="myattr".*?attr2="(.+?)".*?attr3="(.+?)")|(attr1="myattr".*?attr3="(.+?)".*?attr2="(.+?)")|(attr2="(.+?)".*?attr3="(.+?)".*?attr1="myattr")|(attr2="(.+?)".*?attr1="myattr".*?attr3="(.+?)")|(attr3="(.+?)".*?attr2="(.+?)".*?attr1="myattr")|(attr3="(.+?)".*?attr1="myattr".*?attr2="(.+?)")).*?>(.+?)</a>
Input String for different order of attributes:
First <a attr1="myattr" attr2="value12" attr3="value13">text1</a>Second <a attr1="myattr" attr3="value13" attr2="value12">text2</a> Third <a attr2="value12" attr1="myattr" attr3="value13">text3</a>`