MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

Variable order regex syntax problem!

0
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:
 <a href="home.php" class="link" title="Home">Home</a> <a href="home.php" title="Home" class="link">Home</a>
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.


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:

regex

 

parsing

 

PHP

 

Xml

 

Dynamic HTML

 

HTML (Hypertext Markup Language)

 

HTML 4.0

 

HTML5

 

HTML validator

 

Initiator

Caroline
Caroline
  Follow

I love to write & blog.

More posts by: Caroline George

1 Suggestion

  1. 20 December 12
    0



    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+)['"])+ />

Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top