34

Does anyone know if in Gmail you can search all messages that have an exclamation mark in the subject?

I would like to create a filter that adds a red ! label to the messages that have an exclamation mark in the subject. But searching for subject:! results in all messages. I've tried things like /!/, /\!/, (/\!/), "!", but all these searches just give me all messages, not just those with ! in the subject.

21

From the "About Gmail Search" documentation:

Gmail doesn't recognize special search characters like square brackets, parentheses, currency symbols, the ampersand, the pound sign, and asterisks.

As you appear to have already discovered, and my quick tests appear to confirm, this seems to include the exclamation mark character.

I would assume that the regular expression Google are using to match search queries with possible results simply excludes all special characters and operates only on "word characters" (you can somewhat confirm this by the fact that searches for the underscore character, _, do work - the underscore is treated as a word character in a regular expression).

4
  • 1
    Thanks, not what I wanted to hear but at least I know I'll have to figure out something else for my needs.
    – jankeir
    Sep 20 '12 at 8:09
  • What about the dash "-"?
    – Pacerier
    Apr 25 '14 at 9:30
  • The dash in search is a NOT operator. You'll not be able to search for a dash.
    – ale
    Aug 29 '15 at 16:22
  • 4
    @Google for a search company, it really is a HUGE hole in your system that is can't search for special characters. Every other search tech on the planet can do that, but not Google?? tisk, tisk, tisk...
    – MikeyE
    Dec 3 '17 at 22:45
11

With the help of Google Apps Script, you can use regular expressions in Gmail to find messages that have the exclamation mark in the subject.

The same script can be extended to apply Gmail filters to messages that match the expression.

Update: Here's the snippet of Apps Script that should help you find the relevant messages:

var pattern = "^!";
var threads = GmailApp.search("in:inbox");

for (var i = 0; i < threads.length; i++) { 
  var messages = threads[i].getMessages();

  for (var m = 0; m < messages.length; m++) {
      var subject = messages[m].getSubject();
      if (subject.search(pattern) !== -1) 
         Logger.log("https://mail.google.com/mail/u/0/#all/" + messages[m].getId());
  }
}
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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