120

我们在工作中从 Jenkins 构建服务器定期收到自动构建消息。

最好将这些内容收集到标签中,跳过收件箱。

使用过滤器当然是正确的选择。

所需的标识符是[RELEASE]主题行开头的字符串。

尝试指定以下任何正则表达式都会导致带有字符串的电子邮件release在任何情况下都匹配主题行中的任何位置:

\[RELEASE\]*
^\[RELEASE\]
^\[RELEASE\]*
^\[RELEASE\].*

从我随后读到的内容来看,Gmail 没有标准的正则表达式支持,并且从实验看来,就像谷歌搜索一样,特殊字符被简单地忽略了。

因此,我正在寻找可以使用的搜索参数,可能类似于与他们的,符号atstart:mystring保持一致。has:in:

有没有办法强制匹配仅在它发生在行首时,并且仅在包含方括号的情况下?

真诚的感谢。

4

3 回答 3

154

Regex is not on the list of search features, and it was on (more or less, as Better message search functionality (i.e. Wildcard and partial word search)) the list of pre-canned feature requests, so the answer is "you cannot do this via the Gmail web UI" :-(

There are no current Labs features which offer this. SIEVE filters would be another way to do this, that too was not supported, there seems to no longer be any definitive statement on SIEVE support in the Gmail help.

Updated for link rot The pre-canned list of feature requests was, er canned, the original is on archive.org dated 2012, now you just get redirected to a dumbed down page telling you how to give feedback. Lack of SIEVE support was covered in answer 78761 Does Gmail support all IMAP features?, since some time in 2015 that answer silently redirects to the answer about IMAP client configuration, archive.org has a copy dated 2014.

With the current search facility brackets of any form () {} [] are used for grouping, they have no observable effect if there's just one term within. Using (aaa|bbb) and [aaa|bbb] are equivalent and will both find words aaa or bbb. Most other punctuation characters, including \, are treated as a space or a word-separator, + - : and " do have special meaning though, see the help.

As of 2016, only the form "{term1 term2}" is documented for this, and is equivalent to the search "term1 OR term2".

You can do regex searches on your mailbox (within limits) programmatically via Google docs: http://www.labnol.org/internet/advanced-gmail-search/21623/ has source showing how it can be done (copy the document, then Tools > Script Editor to get the complete source).

You could also do this via IMAP as described here: Python IMAP search for partial subject and script something to move messages to different folder. The IMAP SEARCH verb only supports substrings, not regex (Gmail search is further limited to complete words, not substrings), further processing of the matches to apply a regex would be needed.

For completeness, one last workaround is: Gmail supports plus addressing, if you can change the destination address to youraddress+jenkinsrelease@gmail.com it will still be sent to your mailbox where you can filter by recipient address. Make sure to filter using the full email address to:youraddress+jenkinsrelease@gmail.com. This is of course more or less the same thing as setting up a dedicated Gmail address for this purpose :-)

于 2013-02-04T13:23:23.860 回答
1

我发现这样做的唯一选择是找到一些确切的措辞并将其放在“有的话”选项下。它不是最好的选择,但它确实有效。

于 2016-08-12T15:21:09.653 回答
-8

我想知道自己如何做到这一点;似乎 Gmail 已经默默地实现了这个功能。我创建了以下过滤器:

Matches: subject:([test])
Do this: Skip Inbox

然后我发了一条带有主题的消息

[test] foo

消息已存档!因此,似乎只需为您希望处理的主题前缀创建一个过滤器。

于 2014-01-24T04:54:15.420 回答