javascript - Literal dollar sign in a regular expression -
i working canada (fr-ca) locale , trying following:
var str = "<dataset >{1}</dataset>"; var temp = "<set cost x = '1,8m $' />"; str = str.replace(/\{1\}/g, temp);
output:
"<dataset ><set cost x = '1,8m </dataset>" /></dataset>"
desired output:
"<dataset ><set cost x = '1,8m $'" /></dataset>"
replace function misunderstanding $
' '1,8m $'
expression , hence
repeating in output. ideas/workaround? thank time.
$'
has special meaning in replacement string when using js regular expressions: inserts portion of string follows matched substring. literal dollar sign in replacement string, use $$
.
see https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/string/replace.
Comments
Post a Comment