Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hello all,
i am trying to write a regular expression for a html like parser. I want help at a point in parsing the tags, such that it looks for the matching end tag if and only if there is a starting tag written before.

So for example, if in the middle of a string a user can type <a href=""> </a>, and it should check for </a> only if <a> is there, not otherwise. How to match it conditionally ?

Thanks.
Posted

1 solution

use this pattern :)
/(<a( *)href( *)=( *)\")([^\"]*\"( *)>) ([^<]*<( *)/a( *)>)/g
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900