Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Gmail filter searching for text only at start of subject line?

We receive regular automated build messages from Jenkins build servers at work.

It'd be nice to ferret these away into a label, skipping the inbox.

Using a filter is of course the right choice.

The desired identifier is the string [RELEASE] at the beginning of a subject line.

Attempting to specify any of the following regexes causes emails with the string release in any case anywhere in the subject line to be matched:

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

From what I've read subsequently, Gmail doesn't have standard regex support, and from experimentation it seems, as with google search, special characters are simply ignored.

I'm therefore looking for a search parameter which can be used, maybe something like atstart:mystring in keeping with their has:, in: notations.

Is there a way to force the match only if it occurs at the start of the line, and only in the case where square brackets are included?

Sincere thanks.

like image 696
KomodoDave Avatar asked Sep 03 '12 11:09

KomodoDave


People also ask

Can you filter Gmail by subject?

In Settings, click on Filters and Blocked Addresses menu item. Select Create a new filter. In the “Subject” section of the form, enter “Needs Approval” (but you can use any keywords in place of this to use as a filter). Select Create filter button.

How do I search Gmail by subject?

By subject line. With this Gmail search command, you can search for emails by the contents of their subject lines. Use “subject:” followed by a word or phrase you'd like to find. All emails that contain all or part of your search in the subject line will be presented to you.

How do I filter emails with certain words in Gmail?

Go to the Gmail search bar and click on the gray triangle. In the dropdown, navigate to the “Has the words” field and type in is:spam. Click on the “Create filter” button. Use the “Delete it” filter action and confirm filter creation.


1 Answers

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 [email protected] 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:[email protected]. This is of course more or less the same thing as setting up a dedicated Gmail address for this purpose :-)

like image 164
mr.spuratic Avatar answered Oct 31 '22 16:10

mr.spuratic