【发布时间】:2023-04-01 07:42:01
【问题描述】:
在谷歌脚本中,我试图根据它后面的字符替换%string。
我尝试过使用:
var indexOfPercent = newString.indexOf("%");
然后检查indexOfPercent+1的字符,但indexOf只返回第一次出现的'%'。
如何获得所有事件?也许有更简单的方法(正则表达式)?
编辑:
最后,我想将所有出现的% 替换为%%,但如果百分号是%@ 或%@ 的一部分,则不是。
总结一下:我的字符串:Test%@ Test2%s Test3%. 应该是:Test%@ Test2%s Test3%%.
我试过用这样的东西:
//?!n Matches any string that is not followed by a specific string n
//(x|y) Find any of the alternatives specified
var newString = newString.replace(\%?![s]|\%?![%], "%%")
但它没有找到任何字符串。我不熟悉正则表达式,所以也许这是一个简单的错误。
谢谢
【问题讨论】:
标签: javascript regex