Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex stop searching at specific string

Tags:

regex

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/
like image 284
Avraham Avatar asked Oct 19 '25 09:10

Avraham


1 Answers

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

/pattern":"(?<data>.+?)"(?=.+specific string)/si
like image 146
hwnd Avatar answered Oct 21 '25 21:10

hwnd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!