Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Gmail应用程序搜索条件_Regex_String_Google Apps Script_Gmail_Criteria - Fatal编程技术网

Regex Gmail应用程序搜索条件

Regex Gmail应用程序搜索条件,regex,string,google-apps-script,gmail,criteria,Regex,String,Google Apps Script,Gmail,Criteria,我的以下搜索条件在Gmail中运行良好: user@domain from:/mail delivery/ || /postmaster/ ||/Undeliverable/ 我正在尝试编写Goole应用程序代码以返回相同的结果。代码如下: var thread=GmailApp.search("user@domain from:/mail delivery/ || /postmaster/ ||/Undeliverable/ "); 我得到了不同的结果。我对Regex和Google应

我的以下搜索条件在Gmail中运行良好:

user@domain  from:/mail delivery/ || /postmaster/ ||/Undeliverable/ 
我正在尝试编写Goole应用程序代码以返回相同的结果。代码如下:

var thread=GmailApp.search("user@domain  from:/mail delivery/ || /postmaster/ ||/Undeliverable/ ");

我得到了不同的结果。我对RegexGoogle应用程序都是新手。

试试Amit Agarwal的教程,其中包括:

函数搜索(){
var sheet=SpreadsheetApp.getActiveSheet();
var行=2;
//清除现有搜索结果
sheet.getRange(2,1,sheet.getMaxRows()-1,4).clearContent();
//应该搜索哪个Gmail标签?
var label=sheet.getRange(“F3”).getValue();
//获取正则表达式搜索模式
var模式=sheet.getRange(“F4”).getValue();
//检索指定标签的所有线程
var threads=GmailApp.search(“in::+label”);
对于(var i=0;i
我的查询sting在Regex中会是什么样子?
function Search() {

var sheet   = SpreadsheetApp.getActiveSheet();
var row     = 2;

// Clear existing search results
sheet.getRange(2, 1, sheet.getMaxRows() - 1, 4).clearContent();
// Which Gmail Label should be searched?
var label   = sheet.getRange("F3").getValue();
// Get the Regular Expression Search Pattern
var pattern = sheet.getRange("F4").getValue();
// Retrieve all threads of the specified label
var threads = GmailApp.search("in:" + label);

for (var i = 0; i < threads.length; i++) {

  var messages = threads[i].getMessages();

  for (var m = 0; m < messages.length; m++) {
    var msg = messages[m].getBody();
    // Does the message content match the search pattern?
    if (msg.search(pattern) !== -1) {
     // Format and print the date of the matching message
     sheet.getRange(row,1).setValue(
      Utilities.formatDate(messages[m].getDate(),"GMT","yyyy-MM-dd"));
     // Print the sender's name and email address
     sheet.getRange(row,2).setValue(messages[m].getFrom());        
     // Print the message subject
     sheet.getRange(row,3).setValue(messages[m].getSubject());
     // Print the unique URL of the Gmail message
     var id = "https://mail.google.com/mail/u/0/#all/"
       + messages[m].getId();
     sheet.getRange(row,4).setFormula(
       '=hyperlink("' + id + '", "View")'); 
     // Move to the next row
     row++;
   }
  }
 }
}