简体   繁体   English

Google Apps脚本replaceText正则表达式出现问题

[英]Having issues with Google Apps Script replaceText regex

So in my code 所以在我的代码中

body.replaceText("test1","test2"); body.replaceText( “测试1”, “TEST2”);

works and so do simple regexs, but I can't get more complex ones to work. 也可以使用简单的正则表达式,但是我无法使用更复杂的正则表达式。 For example I want to remove all spacing between two tags and replace it with three carriage returns. 例如,我想删除两个标签之间的所有间距,并用三个回车符代替。 I've tested it out in regexr and other tools and it works but it does nothing in my Apps Script. 我已经在regexr和其他工具中对其进行了测试,并且可以正常工作,但是在我的Apps脚本中却没有任何作用。

 body.replaceText("/</em>[\r\n]+<strong>/g","</em>\r\r\r<strong>");

this doesn't work either 这也不起作用

body.replaceText("</em>[\r\n]+<strong>","</em>\r\r\r<strong>");

我尝试了这个,对我有用

body.replaceText("</em>\\[\\\\r\\\\n\\]\\+<strong>", '</em>\r\r\r<strong>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM