I have a string that looks like this
Hello, my name is "{{ @sql(SELECT TOP 1 name FROM table1 WHERE [id] = 5 ) }}" and my title is "{{ @sql(SELECT TOP 1 title FROM table1 WHERE [id] = 5 ) }}"
I need to be able to take this string and parse out any pattern that matches the following pattern {{ @sql(WHATEVER QUERY GOES HERE) }}
it must start with two braken followed by optional spaces and then @sql(
ending in ) }}
Additionally, I will also need to extract the inner query which is the text that is found between @sql(
and ending in ) }}
Here is what I have done
$pattern = '/\{\{\s*+@sql\((.+)\)+\s*+\}\}/i';
$matches = [];
preg_match ( $pattern, $subject, $matches, PREG_OFFSET_CAPTURE );
echo '<pre>';
print_r($matches);
echo '</pre>';
My pattern works for the following string
Hello "{{ @sql(SELECT TOP 1 name FROM table1 WHERE [id] = 5 ) }}"
but when I need to use the pattern more than once in the text, it seems that my pattern search for the last occurrence of )}}
instead of the next occurrence.
How can I update my pattern so it looks for one ore multiple matches?
Thank you