29

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.

17

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).

  • 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
  • 1
    @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());
  }
}
  • Thanks Amit, good suggestion, although I fear that using it will make me run in to the apps script quota's even more than I already do. – jankeir Sep 25 '12 at 10:20
  • True. Can't think of any other workaround though at this time. – Amit Agarwal Sep 25 '12 at 11:00
  • it seems this is also a problem for IMAP mail clients accessing GMail -- stackoverflow.com/q/9589583/94687 . So, just using an exernal IMAP client for such kind of searches is not a solution (unless the client does the filtering itself, without relying on server responses to SEARCH). – imz -- Ivan Zakharyaschev Sep 14 '16 at 12:11

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.