I'm trying to match sth like html tags with regEx. It's sth like that:
Lorem <div class="sth">ipsum dolor <div class="another">sit amet, consectetur</div> adipiscing</div> elit
And my regular expression is:
/<\s*div[^>]*>(.*?)<\s*/\s*div>/g
But it should match first <div class="sth">
with last </div>
and second <div class="another">
with first </div>
. I want both expressions(one of them is inner and other one is outer). So I want to match the regular expressions like HTML does.
Here is the code page: https://www.regextester.com/111196
I'm using JavaScript as the programming language.
EDIT
I'm editing the question beacause of misunderstanding. I gave the expression for just understand it good. Actuall my regex is different:
/\*\*\*.*?\*\*\*.*?\*/\*\*.*?\*\*\*/g
And my text is:
Aenean ***life*** sed consectetur. ***Lorem*** ipsum dolor */**sit*** amet, consectetur */**adipiscing*** elit.
As you see ***${sth}*** is like the opening tag and */**${sth}*** is like the closing tag.
But when I put an expression into another, it confuses. I asked how can handle this situation.
Here is the demo: https://www.regextester.com/?fam=111201