title: How to match everything inside the first pair of square brackets
body: <p>I'm trying to create a <a href="https://datatracker.ietf.org/doc/html/draft-murchison-sieve-regex-08" rel="nofollow noreferrer">regular expression</a> in <a href="https://www.rfc-editor.org/rfc/rfc5228" rel="nofollow noreferrer">sieve</a>. The implementation of sieve that I'm using is <a href="http://wiki2.dovecot.org/Pigeonhole/Sieve" rel="nofollow noreferrer">Dovecot Pigeonhole</a></p>
  <p>I'm subscribed to github project updates and I receive emails from github with the subject in the format that looks like this:</p>
  <blockquote>
  <p>Re: [Opserver] Create issues on Jira from Exception details page (#77)</p>
  </blockquote>
  <p>There is a project name in square bracket included in the subject line. Here is the relevant part of my sieve script:</p>
  <pre><code>if address &quot;From&quot; &quot;notifications@github.com&quot; {
    if header :regex &quot;subject&quot; &quot;\\[(.*)\\]&quot; {
        set :lower :upperfirst &quot;repository&quot; &quot;${1}&quot;;
        fileinto :create &quot;Subscribtions.GitHub.${repository}&quot;; stop;
    } else {
        fileinto :create &quot;Subscribtions.GitHub&quot;; stop;
    }
  }
  </code></pre>
  <p>As you can see from the above, I'm moving the messages to appropriate project IMAP folders. So the message with the subject above will end up in <code>Subscribtions.Github.Opserver</code></p>
  <p>Unfortunately, there is one small problem with this script. If someone adds square brackets in the title of their github issue, the filter breaks. For example if the subject is:</p>
  <blockquote>
  <p>[Project] [Please look at it] - very weird issue</p>
  </blockquote>
  <p>The above filter will move the message to folder <code>Subscribtions.Github.Project] [please look at it</code> which is completely undesirable. I'd like it to be moved to <code>Subscribtions.Github.Project</code> anyway.</p>
  <p>This happens because by default regular expressions are greedy. So they match the longest possible match. However when I try to fix it the usual way changing <code>&quot;\\[(.*)\\]&quot;</code> to <code>&quot;\\[(.*?)\\]&quot;</code> nothing seems to change.</p>
  <p>How do I write this regular expression so that it acts as desired?</p>