我只能够代替我的str中的第一个引号 [英] I am only able to replace the first quotation mark in my str

查看:130
本文介绍了我只能够代替我的str中的第一个引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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>

以上使用常规的前pression逃脱IM的字符串,但它只是做它的第一个

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

我是什么做错了吗?

推荐答案

您需要指定全局标志。请参阅该文档的更换方法

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

 var myPattern:RegExp = /\"/g;

这篇关于我只能够代替我的str中的第一个引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆