Lets sagen, dass wir einige html wie dieses:RegEx, passende Gruppe von HTML-Tags
<html>
<body>
<h2>Match group</h2>
<ul>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
<h2>Match group 2</h2>
<ul>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
<h2>Match group n</h2>
<ul>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
<h2>NOMATCH</h2>
<ul>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
</body>
</html>
Wie können wir alle Gruppen von h2 und ul-Tags extrahieren, wo h2-Tag Match das Wort enthält? Im Grunde muss ich diese Gruppe von Elementen, wie dies ein div-Container hinzuzufügen:
<div id="container">
<h2>Match group 1></h2><ul>...</ul>
<h2>Match group 1></h2><ul>...</ul>
<h2>Match group N></h2><ul>...</ul>
</div>
<h2>NOMATCH</h2>
<ul>...</ul>
H2 und ul-Tags enthalten kann eine beliebige Anzahl von HTML-Attributen.
Das ist, was ich bisher habe: https://regex101.com/r/mR2fT7/1
Wer noch keine Ahnung, wie dies zu tun?
Sie es nicht tun: http: // Stackoverflow .com/questions/3577641/how-do-you-parse-und-prozess-html-xml-in-php/3577662 # 3577662 und http://stackoverflow.com/questions/1732348/regex-match-open-tags -except-xhtml-in sich abgeschlossene Tags? rq = 1 – AbraCadaver