【问题标题】:REGEX find all text within custom tags正则表达式查找自定义标签中的所有文本
【发布时间】:2018-05-09 01:58:26
【问题描述】:

我想创建一个 Gmail 应用程序来捕获此自定义标记 <! some text, blah, blah, blah > 中的所有文本

标签是<! text_to_be_captured_here >

我可以使用什么模式。当然标签内的文字是可变的。

提前致谢。

【问题讨论】:

  • SO 不是代码/SQL/正则表达式编写服务,您可以在其中发布您的要求和选择的语言列表,然后有人为您编写代码。我们非常乐意提供帮助,但我们希望您首先努力自己解决问题。完成后,您可以解释您遇到的问题,包括您工作的相关部分,并提出具体问题,我们会尽力提供帮助。祝你好运。

标签: google-apps-script gmail gmail-addons


【解决方案1】:

假设您计划使用 Google Apps 脚本创建上述应用程序,因为您在发布问题时已包含 google-apps-script 标记。

假设您已经输入了文本并将其存储在变量 string 中,请尝试以下代码:

var string = "Here is some random text that you received as input from your <!Gmail Application>";

var requiredText = "Custom Tag not found!";

if(string.match(/\<\!(.*?)\>/))
{
  requiredText = string.match(/\<\!(.*?)\>/).pop().trim();
}

Logger.log("Text withing custom tag :"+requiredText);

如果日志中的输出是Custom Tag not found!,那么您输入的字符串不包含预定义的自定义标签。

如果是 Custom Tag not found! 以外的任何内容,则表示代码正在运行。

希望这会有所帮助!

【讨论】:

  • 感谢 Suyash !
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-23
  • 2011-04-02
  • 2015-06-07
  • 1970-01-01
  • 1970-01-01
  • 2020-03-21
相关资源
最近更新 更多