You need a "retexp" to select a multi-line portion of text between the numbering of paragraphs. I managed to take only the first line.

Text:

> лалала - текст-шапка ненужный > > 1. > текст текст > текст текст > > 2. > #$!...разные символы > > 3. bla1 bla1 bla1 > бла1 бла1 бла1 > > 4. bla2 bla2 bla2 > bla2 bla2 bla2 > > лалалала - текст-хвост, можно оставить болтаться с пунктом №4 

Regexp (takes only the first line):

 preg_match_all("**/\d\.\n(.*?)$/um**", $input_lines, $output_array); 

The result of this regexp:

array (... 1 => array (4 0 => aaaaaaaaa 1 => # $! ... different characters 2 => bla1 bla1 bla1 3 => bla2 bla2 bla2 bla2))

reference to example (switch to preg_match_all).

Question: how to make a selection of all lines between paragraph numbers?

    1 answer 1

    Use

     /^\d+\.\n(.*(?:\n(?!\n).*)*)$/um 

    See the demo

    Details :

    • ^ - the beginning of the line (line)
    • \d+ - 1+ digits
    • \.\n - point + newline character
    • (.*(?:\n(?!\n).*)*) - Submask number 1:
      • .* - 0+ characters other than newline character
      • \n(?!\n) is a newline character, after which there is no other same character
      • .* - 0+ characters other than newline character
    • $

    PHP demo :

     $re = '~^\d+\.\n(.*(?:\n(?!\n).*)*)$~um'; $input_lines = "лалала - текст ненужный \n\n1.\naaaaaaaaa\n\n2.\n#\$!...разные символы\n\n3.\nbla bla bla\nбла бла бла\n\n4.\nbla bla bla\nлалалала\n\nлалалала - текст-хвост, можно оставить болтаться с пунктом №4\n"; preg_match_all($re, $input_lines, $output_array); print_r($output_array[1]); 
    • one
      It works, thanks! - Sergey Bogdanov