A
A
Alexey Burlaka2018-03-16 20:36:22
Regular Expressions
Alexey Burlaka, 2018-03-16 20:36:22

How to select all pairs of tags in a string?

Tell me, how can I get all pairs of tags with text inside from a string?
For example, we have this line:

<b>Ключ <br> 1:</b>Значение 1<br><b>Ключ 2:</b>Значение 2<br><b>Ключ 3:</b>Значение 3<br><b>Ключ 4:</b>Значение 4<br>

I need to get all occurrences from inside:
<b>Ключ <br> 1:</b>
<b>Ключ 2:</b>
<b>Ключ 3:</b>
<b>Ключ 4:</b>

I try this pattern: ... I try this: ... it grabs me from the very first b tag to the last one. If line breaks are placed - like this:
<(a|p|b)>.*<\/\1>
<(a|p|b)>[^\1]+<\/\1>

<b>Ключ <br> 1:</b>Значение 1<br>
<b>Ключ 2:</b>Значение 2<br>
<b>Ключ 3:</b>Значение 3<br>
<b>Ключ 4:</b>Значение 4<br>

then the pattern gets the right pairs, but if the original text is solid, it doesn't. Tell me how to proceed? <(a|p|b)>.*<\/\1>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-03-16
@AlexeyGfi

Remove greed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question