Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
@"
<div id=""target""((?'nested'<div)|</div(?'-nested')|[\w\W]*?)*</div>
"
gm
Input 1
New
<!DOCTYPE html> <html> <head> <title>someTitle</title> </head> <body> <div class="outer"> <h1>SomeHeader</h1> <div id="target"> <h2>anotherHeader</h2> <div id="child"> <div id="grand-child"> <h4>HelloWorld</h4> </div> </div> </div> </div> </body> </html>
Extraction
<!DOCTYPE html> <html> <head> <title>someTitle</title> </head> <body> <div class="outer"> <h1>SomeHeader</h1> <div id="target"> <h2>anotherHeader</h2> <div id="child"> <div id="grand-child"> <h4>HelloWorld</h4> </div> </div> </div> </div> </body> </html>