Tuesday, 20 August 2013

Regular expression matching unescaped paired brackets and nested function calls

Regular expression matching unescaped paired brackets and nested function
calls

Here's the problem: given a string like
"<p>The price for vehicles {capitalize(pluralize(vehicle))} is
{format_number(value, language)}</p><span>{employee_name}</span><span>\{do
not parse me}</span>"
I need (1) a regex pattern in PHP that matches all values between
un-escaped pairs of curly brackets and (2) another regex pattern that
matches function calls and nested function calls (once the first pattern
is matched). Of course, if I could use one regex only for both tasks that
would be awesome.
By the way, I can't use Smarty, Twig or any other library - that's the
only reason I have to build a parsing mechanism myself.
Thanks a ton!

No comments:

Post a Comment