2

I have a multiple line text file which have blocks of text. Each block starts with name=, block can have variable number of lines. I need to extract these blocks, including name=. Here is my best idea so far:

/(name=.*?)/gs

But it only matches the begging of the block name=, not the whole block.

Live Demo

Vladimir
  • 335
  • 1
  • 3
  • 13

1 Answers1

1
/(name=.*?)(?=name=|$)/gs

You need to give your regex someway to stop. So include a lookahead which would stop regex at next instance of next= or end of string.

halfer
  • 19,471
  • 17
  • 87
  • 173
vks
  • 65,133
  • 10
  • 87
  • 119