Parsing #placeholder# templates when a regex is not enough

Generative Grammar Engine writes rules in Tracery&rsquo;s notation: #name# marks a placeholder, the rest is literal text. To run a rule, the engine first splits a string like #greeting#, #name#! into placeholders and literals. The obvious tool is a regular expression, and it works until someone needs a literal # in their text. Where the regex breaks The common pattern is /#([^#]+)#/g : a hash,…