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.


2 Answers 2


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, 2012 at 8:09
  • What about the dash "-"?
    – Pacerier
    Apr 25, 2014 at 9:30
  • The dash in search is a NOT operator. You'll not be able to search for a dash.
    – ale
    Aug 29, 2015 at 16:22
  • 5
    @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, 2017 at 22:45

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());
  • 1
    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, 2012 at 10:20
  • True. Can't think of any other workaround though at this time. Sep 25, 2012 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). Sep 14, 2016 at 12:11
  • This almost works, but currently searches the body rather than the subject. var msg = messages[m].getBody(); if (msg.search(pattern) !== -1) { ...
    – ijoseph
    Mar 26, 2021 at 22:16

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