【发布时间】:2012-01-25 15:00:06
【问题描述】:
我正在尝试用 Javascript 中多次出现的字符串替换一个字符。
String a1 = "There is a man over there";
当我使用replace("e","x")时;
它将仅替换第一次出现的 e。
所以我正在尝试像这样使用 g 修饰符replace(/e/g,"x");
但我正面临这个错误Syntax error on tokens, Expression expected instead
我不确定我在这里做错了什么。
【问题讨论】:
-
为我工作:
"There is a man over there".replace(/e/g,'x')你的有什么不同吗? -
a1 = "There is a man over there"; a1.replace(/e/g,"x");正确返回“Thxrx is a man ovxr thxrx” -
您已标记您的问题
java和javascript。它们是非常不同的语言。您的replace(/e/g, "x")示例是 JavaScript。从错误中,您是否尝试在 Java 代码中执行此操作? -
猜我混淆了 和
标签: java javascript html jsp syntax