开发者

string.replace(/""\n/g,"\"\""+ "\n") will this work?

开发者 https://www.devze.com 2023-04-06 20:45 出处:网络
strin开发者_开发技巧g.replace(/\"\"\\n/g,\"\\\"\\\"\"+ \"\\n\") I am trying to parse a string and for using JSON parser. I need to replace the occurrence \"\"\\n (quote, quote, newline) with \\\\\"\
strin开发者_开发技巧g.replace(/""\n/g,"\"\""+ "\n")

I am trying to parse a string and for using JSON parser. I need to replace the occurrence ""\n (quote, quote, newline) with \\"\\"\n (slash, quote, slash, quote, newline).

I tried to do this by using escape sequence, but am not able to do so.


Try using the single quote (') string form to avoid escaping double-quotes unnecessarily this:

string.replace(/""\n/g, '\\"\\"\n')


Try this regular expression /\"\"[\n|\r]/g

str.replace( /\"\"[\n|\r]/g, '\\"\\"\r' );

It works for me :)

0

精彩评论

暂无评论...
验证码 换一张
取 消