R
R
RMate2020-06-27 15:05:25
Regular Expressions
RMate, 2020-06-27 15:05:25

How to compose a regular expression to search for nested tags?

Hello! Please help me compose a recursive regular expression to search for tags.

I try to do this:
<([^>]+)>((?R)|.+)<\/\1>
I expect that this regular expression will search for paired tags <b></b>, after which the content will be searched again, and if nothing is found, it will place the content in a separate group.
Testing on a line

<ul><li>1<span>qwe</span></li><div>sometext</div></ul><div></div>.
I can't figure out why it doesn't work.

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-06-27
@dimonchik2013

twist greed
and what is it
((?R)|.+)
why not [^<]+

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question