37

I use Gmail and I'm receiving lots of emails I want to filter. They all have in common that the subject is like these:

Some words - r1234 - Some more words
Some words - r987665 - Some more words
Some words - r01 - Some more words

So, all of them have something like - r... - in the subject...

Is there any way to filter all those messages?

1
  • 2
    Ah, do "Some words" and "Some more words" vary each time? In that case my suggestion wouldn't work. I perhaps wrongly assumed that these two phrases were consistent among these emails? (Also, just realised that gmail doesn't seem to like searching for part words, so "wor" wouldn't find "word"!)
    – MrWhite
    Sep 24, 2013 at 15:08

9 Answers 9

23

Googles help article 7190 lists the search operators you can use in Gmail. This article lists the AROUND keyword mentioned by RADA.

Currently, using the * (SHIFT 8) also works. I use it as *=AnyTextHere.

e.g. "Ticket* for user" find Ticket 1 for user and Ticket 2 for user and Ticket 1000 for user.

3
  • 1
    This not working for me in to search eg to:(some_id*@some.email)
    – Nam G VU
    Dec 2, 2019 at 1:57
  • 6
    The original question was about filtering on the subject line. You are trying to filter on the to: field. Using to:*@some.email or to:@some.email works. Your request to use to:string*@some.email does not. Maybe Google uses To & From fields differently than the Subject? Dec 3, 2019 at 6:13
  • Thanks for clear explain @IanC. Using AROUND works nicely now.
    – Nam G VU
    Dec 3, 2019 at 6:24
7

For Gmail filtering you first need to construct the "Search Operators." Although it's not a regular expression, you can still achieve what you want.

Some words - r1234 - Some more words

Would be something like "Some words AROUND 1 Some more words"

Find messages with words near each other. Use the number to say how many words apart the words can be

AROUND

Example: holiday AROUND 10 vacation

Add quotes to find messages in which the word you put first stays first.

Example: "secret AROUND 25 birthday"

Here is the official help

I ended up here because I was trying to reduce the number of separate filters I had and wanted to group them together. After reading the reference my messages are all clean.

from:("Twitter" OR "Facebook")

6

Short answer

Gmail doesn't include search features such wildcards or regular expressions.

Alternatives

Use the Gmail API, Google Apps Script or third party application that include search features like wildcards or regular expressions.

References

Search in Gmail - Gmail Help

2
6

Filtering "From" with:

*@someemail.com OR *@someothermail.com

Works for me.

1
  • 1
    Question is about doing it with regular expression on subjects. Jun 27, 2018 at 14:22
4

With this syntax, I was able to filter the right items. [*]

Real Life Example that I experienced.

marketing.2232322276.3231244.0@informationservices.hsbc.com.ph
marketing.2667489935.2768504.0@informationservices.hsbc.com.ph
marketing.2666668490.7685749.0@informationservices.hsbc.com.ph

So basically, their template is marketing[generated number]@informationservices.hsbc.com.ph

In order for me to filter it out, I did marketing[*]@informationservices.hsbc.com.ph

1

You can achieve this with google's AROUND keyword.

For example, I have a filter set up to delete emails with the subject line like "Your December 2018 Transaction History". To match any change in dates, I've set the subject to "Your AROUND Transaction History". It works perfectly.

0

Using Google Apps Script, you can use this function to filter email threads by a given regex:

function processInboxEmailSubjects() {
  var threads = GmailApp.getInboxThreads();
  for (var i = 0; i < threads.length; i++) {
    var subject = threads[i].getFirstMessageSubject();
    const regex = /- r\d.* -/; //change this to whatever regex you want, this one should cover OP's scenario
    let isAtLeast40 = regex.test(subject)
    if (isAtLeast40) {
      Logger.log(subject);

      // Now do what you want to do with the email thread. For example, skip inbox and add an already existing label, like so:
      threads[i].moveToArchive().addLabel("customLabel")
    }
  }
}

As far as I know, unfortunately there isn't a way to trigger this with every new incoming email, so you have to create a time trigger like so:

function createTrigger(){ //you only need to run this once, then the trigger executes the function every hour in perpetuity
  ScriptApp.newTrigger('processInboxEmailSubjects').timeBased().everyHours(1).create();
} 
-1

I haven't tried regex, but the current help doc specifies (with examples) the operators you can use to filter search results.

https://support.google.com/mail/answer/7190?hl=en

0
-3

I just want to update this post since it has incorrect (or outdated ) information. Gmail does support wildcards. I have the following wildcard set up for subject Privacy Policy ...and it works great. I don't want those words to apply to body since it can be at the bottom of most emails.

Like so: * Privacy Policy *.

2
  • 1
    I think you'll find that "subject:privacy policy" works just as well. It's still not wildcard support.
    – ale
    Dec 6, 2019 at 23:32
  • Just to clarify, I'm talking about setting filters not searching. But you are right about not needing the *. I just added Privacy Policy and it found it even when they were NOT the first words in the subject. I could swear it would not work the first time I tried it. Maybe it took a minute to update. Also so people do not get confused, GMAIL adds "subject:" on its own when using the setup screen. Dec 8, 2019 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.