4

I'm trying to get any character after a repeated specific pattern BUT I need to stop the search at a specific string. For example:

anything anything anything:"pattern":"string" anything anything anything "pattern":"another_string" specific string anything anything anything

So I need to stop the regex at specific string

I have this regex:

/pattern":"(?<data>.+?(?="))/

So the result will be:

Match 1: data = **string**; 
Match 2: data = **another_string**

But it doesn't stop at specific string

I tried this regex but it doesn't work:

/pattern":"(?<data>.+?(?=")).+specific string/
Avraham
  • 537
  • 7
  • 23

1 Answers1

5

You would need to use a lookahead to assert that "specific string" follows somewhere in the string.

/pattern":"(?<data>.+?)"(?=.+specific string)/si
hwnd
  • 69,796
  • 4
  • 95
  • 132