There is a text

<name>Иванов</name><family>Сергей</family><otch>Петрович</otch><age>37</age><name>Васечкин</name><family>Юрий</family><otch>Антонович</otch><age>16</age><name>Яковлев</name><family>Павел</family><otch>Александрович</otch><age>25</age><total>115</total> 

How to highlight this gap:
http://joxi.ru/gkrDpqjNH9erpX.png?d=

Tried to make this regular

 ((?<=<name).+?(?<=</total>)) 

Selects the entire text for some reason.

  • echo substr ($ str, strrpos ($ str, '<name>') - 1); - Deonis

3 answers 3

 (<name>[А-Яа-я]+</name>(<family>[А-Яа-я]+</family>)?(<otch>[А-Яа-я]+</otch>)?(<age>\d+</age>)?<total>\d+</total>) 

It's all right?

 (<name>[А-Яа-я]+</name>(<family>[А-Яа-я]+</family>)?(<otch>[А-Яа-я]+</otch>)?(<age>\d+</age>)?(?=<total>)) 

Or so, if the last tag is not needed.

  • And how to make, that only copied selection in which there is no total tag? - Radzhab
  • Added a line below. - _Aleksandr_

Well ... it is clear why the whole:

IvanovSergeiPetrovich37VasechkinYuriyAntonovich16YakovlevPavelAleksandrovich25115 **

Instead. +? use a reject entry construct.

Better yet, use an xml parser .

 /<name>((?!<name>).)+<\/total>/