HTML tags with Regex

Asked

Viewed 210 times

2

Here’s the thing, I’m 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’d like him to get the right div, which is:

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

But it returns until the first < /div>:

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

Does anyone know what it can be?

NOTE: I’m doing it in java (android)

3 answers

1

How about

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

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

Ha! In Html5 there are no regular expressions.

1

You should transform the possessive quantifier (possessive quantifier) +? in a greedy quantifier (Greedy quantifier) *

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

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

0

Hello, Marcelo.

You did not clearly explain what you want to do, but I understood that you are doing a trick, 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 want.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.