在 AS3 字符串中查找和替换
Find and replace in an AS3 String
我想在另一个字符串中找到“(*”字符串,然后替换它
使用 < 和 / 一个但是方法 replace() 不能做到这一点。
抱歉,我不能把描述中的字符串写在一起 :D
这是我的代码:
//Call the method like..
trace(searchandreplace("(*Foo)"));
private function searchandreplace(input:String):String{
var pattern:RegExp = /(*/gi;
return input.replace(pattern,"</");
}
Trace: //What I get:..
"(*Foo)"
Trace: //What I want...
"</Foo>"
如果有人能解决我的问题就好了。
提前致谢!
您需要在您的模式中屏蔽“(”和“*”:
var pattern:RegExp = /\(\*/gi;
我想在另一个字符串中找到“(*”字符串,然后替换它 使用 < 和 / 一个但是方法 replace() 不能做到这一点。 抱歉,我不能把描述中的字符串写在一起 :D
这是我的代码:
//Call the method like..
trace(searchandreplace("(*Foo)"));
private function searchandreplace(input:String):String{
var pattern:RegExp = /(*/gi;
return input.replace(pattern,"</");
}
Trace: //What I get:..
"(*Foo)"
Trace: //What I want...
"</Foo>"
如果有人能解决我的问题就好了。
提前致谢!
您需要在您的模式中屏蔽“(”和“*”:
var pattern:RegExp = /\(\*/gi;