Use Custom Regex to Link Anywhere On Bitbucket

By on June 18, 2012

A few weeks ago we introduced Bitbucket Links, which among other things makes it possible to integrate Bitbucket to your JIRA issue tracker by using issue keys in your commit message. We have just rolled out an update for this feature that allows you to specify custom regular expressions and custom replacement URLs. Link your repositories to content that matters to you without having to wait for the Bitbucket team to roll out support for it.

To link your own custom regex and replacement URLs, enter the Links configuration in a repository’s Admin settings. Bitbucket supports the Python regex replacement syntax, and you can reference your regex capture groups in your replacement URL via the syntax \1, \2.

For example, the URL\1 matched with the regex (BB-\d+) will link your JIRA issue keys that start with BB-.

We were going to include this functionality when we originally launched the feature but we were worried about the effect of ReDoS on Bitbucket’s performance. However, thanks to the power of Erik’s awesome interrupting cow utility, we are able to bound the total execution time of the linking we perform and push out this feature.


  • Anonymous
    Posted June 18, 2012 at 4:23 pm | Permalink

    I’ve just tried it and it doesn’t seem to work. “#(d+)” does nothing, and “#d+” makes the repo crash with “oops, error”.

    • Dylan Etkin
      Posted June 18, 2012 at 5:33 pm | Permalink

      Hi hsoft,

      The regex #(d+) is the system regex for issue links. System regex’s will take precedence over user provided regex’s.

      The second thing is a bug and I have rolled out a fix for that. So if you are referencing a capture group in your url that does not exist in the regex it will just not link the content.



      • Anonymous
        Posted June 18, 2012 at 6:37 pm | Permalink

        If I understand correctly: if I use the format #123 in my commit messages to link to an external ticket system, I’m out of luck and can’t use the feature?

        • Dylan Etkin
          Posted June 18, 2012 at 6:55 pm | Permalink

          Thats correct. Links to commit hashes, bb issue keys, mentions, pull requests, repos and emoji are all reserved patterns so there can be a consistent expectation of markup across the site.

          • Posted December 8, 2012 at 5:16 pm | Permalink

            Translated – you’re required to use an Atlassian issue tracker in order to properly use this feature. #123 is obviously a very common pattern for citing tickets, regardless of system, so this seems like a sales driven decision rather than a usability one, which is disappointing.

            Surely the user’s regex should be allowed to override Atlassian-specific ones? I could understand the built in ones taking precedence if JIRA integration or the BB issue tracker is enabled – but I’ve just tried on a repo with both these disabled and #(d+) still doesn’t work.

          • Brill Pappin
            Posted December 17, 2014 at 8:09 am | Permalink

            The patter doesn’t have to be the same. Can’t you use a slightly different pattern for your external links?

          • Posted July 1, 2015 at 8:22 am | Permalink

            I’m trying to link to pivotal tracker. I tried `pt-(d+)` since `#(d+)` is reserved. The ui attempts to link those to commit hashes (i guess because of the length?). So, if “commit hashes” are links that cannot be overridden, does that mean there’s no way to link to Pivotal Tracker, or any system that uses 8 digits for issues?

          • Erik van Zijst
            Posted July 1, 2015 at 1:10 pm | Permalink

            A quick look at the source seems to indicate that that might indeed be the issue. Our commit hash matcher eagerly consumes [da-f]{7,40}.

            Now I agree that not being able to override these internal pattens is problematic for these very reasons and so I’ll reprioritize that public issue.

  • normanr
    Posted June 18, 2012 at 4:36 pm | Permalink

    How do you around having to run the interrupting cow reg ex code on the main thread?

    • Posted June 18, 2012 at 5:34 pm | Permalink

      We use Gunicorn ( to run Bitbucket which is a classic pre-forked daemon using single threaded worker process.

      Each worker processes requests in its main thread, which is ideal for interruptingcow.

  • manypeopledesign
    Posted June 22, 2012 at 6:13 am | Permalink

    Logos Site[] Similar Sites : Taiwan,Hong Kong Logos Site[] China Logos Site[]