Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to filter mails by subject with a regular expression.

The subjects I want to match are read like [git-foo] some more text where foo is the string I want to check for.

I end up with the following

require ["fileinto", "variables", "regex"];

if header :regex "subject" "^\[git-.*\]" {
    set :lower :upperfirst "repository" "${1}";

    if string :is "${repository}" "" {
        fileinto "Test/default";
    } else {
        fileinto "Test/${repository}";

Replacing first if statement with if header :matches "subject" "[git-*" { files mails into Test/Foo] some more text but, when correcting "[git-*" to "[git-*]", mails do not match.

Regular expression works with grep -e.

What to do to file mail correctly into Test/Foo?

share|improve this question

Does this regex works instead?


share|improve this answer
Using Thunderbird to set sieve scripts, saving fails: "error: invalid regular expression '[git-(.*)]' for regex match: invalid range end." I also used double quotation marks, otherwise I get way more errors. – Jan Feb 14 '14 at 21:28

You need to escape twice, so that \[git-.*\] becomes \\[git-.*\\]

share|improve this answer

You need to combine both capture groups and double backlashes. Both were mentioned in previous answers, but separately.

if header :regex "subject" "^\\[git-(.*)\\]" {
  set :lower :upperfirst "repository" "${1}";
  // ...


  • unlike :matches, :regex only sets match variables ($1, etc.) for the capture group. :matches sets them for each wildcard.

  • :regex does indeed require escaping [ and ], but with a double backslash.

share|improve this answer

Might be a bit late now, but I found that I had to specify folders with dots instead of slashes: eg. 'fileinto "Test.default"'.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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