If you want to combine everything between the first and third (!) Double quotes (the third is not necessarily the last, you said), you can use a template like this:
$string = '_name=foo"bar"test" more text"'; // This pattern will not include the last " (note the 2, not 3) $pattern = '/_name=((.*?"){2}.*?)"/'; preg_match($pattern, $string, $m); echo $m[1];
Output:
foo"bar"test
Original answer:
I'm not sure if I got you right, but it looks like you want to do the so-called greedy match, which means you want to match the string to the last " , regardless of whether the string contains multiple " s.
To fulfill the greedy coincidence, just let go ? , eg:
_name=(.*)"
You can try it here: https://regex101.com/r/uC5eO9/2
hek2mgl
source share