Regex and Handlebars
binding, handlebars.js, javascript, model-view-controller, regex
Solution
`/{([^{}]+)}/g` should have the behavior you describe:
"cat dog".replace(/{([^{}]+)}/g, "$1") => "cat dog"
"{cat} {dog}".replace(/{([^{}]+)}/g, "$1") => "cat dog"
"{{cat}} {{dog}}".replace(/{([^{}]+)}/g, "$1") => "{cat} {dog}"
Problem
I'm currently working on a set of components (http://github.com/bredele) that you can assemble to get the same kind of features that you have in some JavaScript framework such as Olives.js, Canjs or Angular. One of the component allows you to bind live dom to an object with handlebars.I use the regex (/{([^}]+)}/g) to match only simple handlebars. I would like to match double handlebars as following: before: {label} //return 'label' after: {label} //return 'label' {{label}} //return '{label}' The regex should allow the two use cases. Any idea? Thanls