fork download
  1. <?php
  2. $string = '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 ) }}"';
  3.  
  4. $regex = '~
  5. \{{2}\h*@sql\( # start of outer part
  6. (?P<query>[^()]+) # inner query
  7. \)\h*\}{2} # end of outer part
  8. ~x';
  9.  
  10. $string = preg_replace($regex, '$1', $string);
  11. echo $string;
  12. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Hello, my name is "SELECT TOP 1 name FROM table1 WHERE [id] = 5 " and my title is "SELECT TOP 1 title FROM table1 WHERE [id] = 5 "