jsrender - Replace $& regex group -


boris moore's great jsrender library has 1 bug. neither understand meaning of $&(lastmatch) in regex replace groups nor have idea how resolve.

this article telling me to not use function in production environments, , indirectly not use jsrender live.

could explain me , give replacement of line:

tmplfn(tmplormarkup.replace(rescapequotes, "\\$&"), tmpl); 

regards

edit: hopeless

unfortunately jsrender , jdk leave other holding baby. jsrender says: $% works fine, jdk never specified , not bug.

that not in fact bug. mdn article link non-standard regex.lastmatch() api, programmatic way of accessing last match. jsrender not using api.

in fact jsrender using "$&" replacement pattern in replacement string, in somestring.replace(regex, replacementstring) call - standard usage in javascript regex scenarios.

see https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/string/replace, says:

the replacement string can include following special replacement patterns: ... $& inserts matched substring.

the regex in line of code rescapequotes, declared rescapequotes = /['"\\]/g - , valid javascript regex.

that line looking ' " or\ , replacing them same character preceded \.

incidentally should not trying run same regex expressions used in jsrender if java regex expressions, since in java rules , validity of regex expressions can quite different. jsrender of course runs in javascript environment - browser, or node.js on server...


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -