I am only able to replace the first quotation mark in my str

送分小仙女□ 提交于 2019-12-12 05:16:57

问题


Code:

 var myPattern:RegExp = /\"/;

 trace(a.replace(myPattern, "\\\""));

<TEXTFORMAT LEADING=\"2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">sdfdsfdsf</FONT></P></TEXTFORMAT>

above im using that regular expression to escape the " in the string. however it only does it for the first "

What am I doing wrong?


回答1:


You need to specify the global flag. See the docs for the replace method.

 var myPattern:RegExp = /\"/g;


来源:https://stackoverflow.com/questions/3392846/i-am-only-able-to-replace-the-first-quotation-mark-in-my-str

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!