I have string similar to this one:
{{something1}} something2 {{something3}} something4
How can I match only "something1" using the preg_match() function?
I tried:
preg_match("/\{\{(.*)\}\}/si",$content,$matches);
but this matched too much, returning
something1}} something2 {{something3
I tried adding \b to the pattern, but didn't get what I want that way either.
Could you please help me with this?
a full answer - if our $var is:
STARTT 
FIRST KKK
SECOND KKK
1) In case we use:
$var = preg_replace('/STARTT(.*)KKK/', 'REPLACED-STRING', $var);
it will change everything from the STARTT to last KKK and Result will be:
REPLACED-STRING
2) In case we use:
$var = preg_replace('/STARTT(.*?)KKK/', 'REPLACED-STRING', $var);
Result will be:
REPLACED-STRING 
SECOND KKK
                        Use non greedy modifier ? :
preg_match("/\{\{(.*?)\}\}/si",$content,$matches);
             here --^
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With