HTML tags with RegEx

2

It is as follows, using the following expression:

<div class="teste">(.+?)</div>

And that's the content, for example:

<div class="teste">asdasdad<div>zxczxczxc</div>lkjlkjjlkj</div><div>asdasd</div>

I would like it to take the correct div, ie:

<div class="teste">asdasdad<div>zxczxczxc</div>lkjlkjjlkj</div>

But it returns to the first < / div>:

<div class="teste">asdasdad<div>zxczxczxc</div>

Does anyone know what it can be?

NOTE: I'm doing this in java (android)

    
asked by anonymous 20.07.2014 / 06:18

3 answers

1

How about

var conteudo = document.getElementsByClassName('teste')[0].InnetHtml;

It will return all content inside the test div .. only inside it.

Ha! In html5 there are no regular expressions.

    
20.07.2014 / 15:50
1

You should turn the possessive quantifier +? into a greedy quantifier *

<div class="teste">(.*)</div>

This will make the regex check to the end of the line and get the last occurrence of </div> and include all possible characters that are not line breakers ( \n )

    
07.04.2017 / 20:11
0

Hello, Marcelo.

You have not clearly explained what you want to do, but I understand that you are making a hassle, it would be easier if you simplified the code, where it is much easier to use logic.

Ex:

<div class="teste">asdasdad</div> <div class="teste">zdsasfsaf</div>

You can use an already created div, as many times as you like.

ABS: I tried to help, from what I understood in your post = D

    
20.07.2014 / 10:00