jquery - Javascript str.replace with dollar sign not working -
sample string being replaced:
https://fw.adsafeprotected.com/rjss/bs.serving-sys.com/52023/7720220/burstingpipe/adserver.bs?cn=rsb&c=28&pli=1234567890&pluid=0&w=300&h=600&ord=[timestamp]&ucm=true&ncu=$${click_url_enc}$&adsafe_preview=${is_preview}`
replacements i'm trying make:
$${click_url_enc}$ --> $$${click_url_enc}$$ [timestamp] --> ${cachebuster}
desired output:
https://fw.adsafeprotected.com/rjss/bs.serving-sys.com/52023/7720220/burstingpipe/adserver.bs?cn=rsb&c=28&pli=1234567890&pluid=0&w=300&h=600&ord=${cachebuster}&ucm=true&ncu=$$${click_url_enc}$$&adsafe_preview=${is_preview}
code i've tried:
code:
var v = $("textarea#creative-content").val(); v = v.replace(/\$\$\{click\_url\_enc\}\$/g, "$$${click_url_enc}$$"); v = v.replace("[timestamp]","${cachebuster}"); console.log(v);
output:
- changed
[timestamp]
${cachebuster}
: yes - changed
$${click_url_enc}$
$$${click_url_enc}$$
: no
code:
var v = $("textarea#creative-content").val(); v = v.replace("$${click_url_enc}$", "$$${click_url_enc}$$"); v = v.replace("[timestamp]","${cachebuster}"); console.log(v);
output:
- changed
[timestamp]
${cachebuster}
: yes - changed
$${click_url_enc}$
$$${click_url_enc}$$
: no
code:
var v = $("textarea#creative-content").val(); v = v.replace("\$\${click_url_enc}\$", "\$\$\${click_url_enc}\$\$"); v = v.replace("[timestamp]","${cachebuster}"); console.log(v);
output:
- changed
[timestamp]
${cachebuster}
: yes - changed
$${click_url_enc}$
$$${click_url_enc}$$
: no
how can make changes i'm looking using javascript/jquery?
in replacements $ special char used when capture group, needs escaped...with $ signs, gives not readable, this:
'$${click_url_enc}$'.replace(/\$\${click_url_enc}\$/g, '$$$$${click_url_enc}$$$');
Comments
Post a Comment