Reputation: 872
I have crazy amount of backslashes in some of my JSON strings.
example:
{"xpath":"//*[@id=\\\\\\\\"pagination_contents\\\\\\\\\\\\"]/div[3]/div/div/form/div[2]/a","title":"keyword"}
I would like to shave anything more than \"
so \\\\\\\\"
would be \"
. Any amount of \\\\
would be trimmed.
I tried
str.replace("\\\"","\"") and not sure how to account for varying amount of backslashes.
Upvotes: 1
Views: 32
Reputation: 5282
.replace(/\\\\+/g, "\\")
should do the trick
for example "abc\\\\\\\\\\\\\\\\def\\\\\\\ghi".replace(/\\\\+/g, "\\")
will return "abc\def\ghi"
Upvotes: 1