is posible use sub result regexp make entire regexp, consider snippet:
var ret = "{hello} {world}"; ret = ret.replace(/(^|[^{}])(\{|\})([^{}]|$)/g, '$1$2$2$3'); ret; // {{hello}} {{world}}
but when put }{
above regexp fail, makes sense cause i'm testing against none of }{
or beginning of string , 1 of {}
, again none of {}
or end of string:
var ret = "{hello}{world}"; ret = ret.replace(/(^|[^{}])(\{|\})([^{}]|$)/g, '$1$2$2$3'); ret; // {{hello}{world}}
is posible use frist result set make second , again make third:
/(^|[^{}])($1)([^{}]|$)/g, '$1$2$2$3' // $1 - or
i'm avare of can use multiply ·replace
method calls cool have one.
thanks
don't consider readability of code.
does 1 regexp work you?
ret.replace(/[{]+(.*?)[}]+/g, '{{$1}}')
p.s.: not sure trying achieve.
Comments
Post a Comment