The title is probably confusing, but I have no idea how to properly phrase this.
So here's my goal. I have this string (or something like it):
[some_element]Random string chars [some_element]Ramdon[/some_element] some more random chars[/some_element]
(Some of you may recognize that these are WordPress shortcodes, but this methodology would still be useful elsewhere to me as well.)
What I need to do is match the parent "element". My usual approach might be something like this:
\[(\w+)].*?\[\/\1]
The problem is, this won't work in the above example, because it's "child element" has a the same closing "tag".
How could I get this regex to work, reglardless of how many nested children exist (literally, an infinite number of duplicate nested children)?