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
  • 361
  • 1
  • 3
  • 14

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,824
  • 17
  • 99
  • 186
vks
  • 67,027
  • 10
  • 91
  • 124