1
I am trying to select a part of an HTML code with Regex but I am not able to do the correct regular expression, someone could give a help?
I need to select the groups of <li>
separately, i.e., without the presence of the tag <br>
in the middle.
For example, I’m trying with the expression below:
/<li.*(?!<br).*\/li>/gi
And I need to select the following text separately:
<li>Teste 1</li><li>Teste 2</li><li>Teste 3</li>
In this test, i created two occurrences from that list, but the expression is selecting everything from the first occurrence to the last.
How do I select the two lists separately?
But there’s another detail, I wanted you to take 2 groups and not each item on the list (which is 6), there’s no way?
– Roger Wolff
Now I’m not on the computer, but I’ll see as soon as I can. Anyway, I think an HTML parser might be better than regex
– hkotsubo
@Rogerwolff I edited the answer, adding this other case (2 groups instead of 6)
– hkotsubo
But I still think it’s better to use an HTML/XML parser. Regex is nice, but is not the best tool to make HTML Parsing.
– hkotsubo