Search code examples
regexanchorhref

Matching anchor tag attribute regardless of order


I am trying to write a regex match for anchor that should check data-username attribute in any order.

<a href="abac" class ="myclass" data-username = "username">Binod</a>

and

<a data-username="username" class ="myclass" href="abac">Binod</a>

Solution

  • Regex solved my problem. <a\ .*?data-username=.*?>(?<linktext>.*?)</a>