1

I need regexp for match all newlines to first match.

Example text:

<p>[Block 1]</p>
<h4>Heading</h4>
<p>Dolor</p>
<p>Ipsum</p>
<p>Lorem</p>
<p>[Block2]</p>
<table>
<tbody>
<tr>
<td>Example</td>
</tr>
<tr>
<td>Example</td>
</tr>
</tbody>
</table>

I wrote this regexp

/<p>\[(.*)\]<\/p>(.*?)/gm

But this regexp doesn't match newlines to first match. I need array:

[0] =>
     [0]=>'Block 1';
     [1]=>'...Html code... before next [block #]';
[1] =>
     [0]=>'Block 2';
     [1]=>'...Html code... before next [block #]';
marts
  • 104
  • 5
  • 2
    This a typical question to match text between two same patterns or end of string, use `'/

    \[(.*?)]<\/p>(.*?)(?=

    \[.*?]<\/p>|\z)/s'`, see [demo](https://regex101.com/r/WcbDZn/1).

    – Wiktor Stribiżew Dec 12 '19 at 09:35
  • 1
    "Match newlines to first match" ? Anyway, you should use a DOM parser for this. – Jeto Dec 12 '19 at 09:35
  • @WiktorStribiżew Thank you very much! Could you post as answer? I'll mark it. – marts Dec 12 '19 at 09:39

0 Answers0