用于替换 actionscript 3 中的字符串的正则表达式
Regular expression to replace string in actionscript 3
我的正则表达式是:
/(url="\S+")/
我的字符串是
<code url="http://ns.adobe.com/textLayout/2008"><p>"test"</p></code>
我想用空字符串替换此 url 值。
str=str.replace(/(url="\S+")/, "");
但是输出像
<code </p></code>
我想要这样的输出:
<code ><p>"test"</p></code>
谁能告诉我我哪里错了???
你应该使用str=str.replace(/(url="[^"]+")/, "");
,它更安全。
见example。
问题出在 \S+
上,这意味着 尽可能多地匹配任何非白色 space 字符 [^\r\n\t\f ](贪婪) 包括 <
和 >
.
我的正则表达式是:
/(url="\S+")/
我的字符串是
<code url="http://ns.adobe.com/textLayout/2008"><p>"test"</p></code>
我想用空字符串替换此 url 值。
str=str.replace(/(url="\S+")/, "");
但是输出像
<code </p></code>
我想要这样的输出:
<code ><p>"test"</p></code>
谁能告诉我我哪里错了???
你应该使用str=str.replace(/(url="[^"]+")/, "");
,它更安全。
见example。
问题出在 \S+
上,这意味着 尽可能多地匹配任何非白色 space 字符 [^\r\n\t\f ](贪婪) 包括 <
和 >
.