PDA

View Full Version : Matching HTML tags



pucara_faa
20th January 2010, 13:58
Hi again!
I need to match HTML tags (when one tag opens and when it closes). If I have

<span class="css1">Some text</span>
It's very easy to match it. But I can't match them correctly when the following happens:

<span style="font-weight: bold">So<span style="color:#F00">me</span> text</span>
The first opened tag matchs the first closed tag, not the last one.

If someone can give me an example or tell me how to do it, I'll be really thanked.
Thanks in advanced.
I'm sorry for my poor English, I'm Argentinian

Lykurg
20th January 2010, 17:41
If it is only one nested tag you could use something like:



<[^>]+>([^<]*| NESTED )</[^>]+>


with NESTED like



<[^>]+>[^<]*</[^>]+>


So you get:



<[^>]+>([^<]*|<[^>]+>[^<]*</[^>]+>)</[^>]+>


But that approach is not very save...

pucara_faa
20th January 2010, 18:34
Thank you very much for answering back!
I'm getting on the right way with the code you gave me. But, I always capture the same expression. How can I match another expression?
For example, in this string:

<span style="font-weight: bold">So<span style="color:#F00">me</span> text</span>
I always match

<span style="color:#F00">me</span>
What if I want to match the first tag (I'm sorry, I'm newbie with this)
Again, thank you.

Lykurg
20th January 2010, 20:39
I am not sure what you really want to achieve but to match also the whole just put brackets at the front and at the end: (PaternToMatch)

pucara_faa
22nd January 2010, 14:19
And what if I have two or more nested tags?