Hello everyone, here is an example: https://regex101.com/r/yO2bD5/1

The problem is that the sought is allocated from the first <hr /> to the last </p> while selecting both pieces, in the database this situation leads to the fact that the result is generally a lot of excess. How could we find these segments each separately?

    2 answers 2

    Easier like this:

     array_filter(preg_split('@<hr\s*\/>\s*@', $yourText), function($e){return trim($e) !== '';}); 

    The proposed text will share as necessary and filter to remove empty lines.
    If you basically need to find a regular, then something like this:

     <hr\s*\/>\s*[\\n]*\s*(.+<\/p>) 

    https://regex101.com/r/yO2bD5/2

      Invert the quantifier "greed" * using the sequence *?

       <hr \/>[\\n]*<h3 class="brown art">Базовая[\s\S]*?и сборкой:<\/p> 

      In this case, it will capture not the maximum possible, but the minimum possible number of characters.