Variable order regex syntax problem!
Started on: 20 December 12
Participants: 1
Is there a way to indicate that two or more regex phrases can occur in any order? For instance, XML attributes can be written in any order. Say that I have the following XML:
Home Home
How do I write a match that checks the class and title and works for both cases? I need it to be able to check in any order, not just matching the class and the title.
This challenge is listed under
Open Source
and Development & Implementations
Community
Related Posts:
1 Suggestion
You can try named groups to pull the attributes out of the tag. Then run the regex and then loop over the groups doing whatever tests that you need.
Something like this (untested, using .net regex syntax with the \w for word characters and \s for whitespace):
<a ((?<key>\w+)\s?=\s?['"](?<value>\w+)['"])+ />