正则表达式-Google Apps脚本 [英] Regex - google apps script
本文介绍了正则表达式-Google Apps脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用正则表达式提取电子邮件文档的子字符串.我正在在线测试正则表达式,它可以完美运行:
I'm trying to extract a substring of a email document with a regular expression. I'm testing the regex online, and it works perfectly:
我有一个功能可以检查Google Apps脚本上的正则表达式,而同一个正则表达式在这里不起作用.
I have a function to check the regex on Google Apps Script and the same regex isn't working here.
var regex = new RegExp("Intrusion signature\(s\)\:\n\n(.*)");
var e = regex.exec(data);
有人知道为什么不起作用吗?
Does anyone knows why is not working?
推荐答案
使用文字正则表达式而不是将字符串转换为正则表达式是可行的.
Using a literal regex instead of converting the string to a regex works.
var regex = new RegExp(/Intrusion signature\(s\)\:\n\n(.*)/);
这篇关于正则表达式-Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文