Stash Jira key pattern false positives

I am no expert on regular expressions. I have the following key pattern:


This is so our Jira project codes match out company coding system. However the following code in a commit is detected as a Jira Issue (CLC0001-1):

prepare release 4701-CLC0001-1.0

Can I improve the key pattern to ignore this kind of match?

2 answers

1 accepted

0 votes
Answer accepted

Hi again Mark,

I think this will do the trick:


To explain, the first part:


Is a positive lookbehind that means the matched key must be at the start of a line (^) or immediately after a character that isn't in the range a-z, A-Z, 0-9 or a -.

The middle part:


Matches one or more characters in the range a-z, A-Z or 0-9; followed by a dash; followed by one or more numbers.

The last part:


Is a positive lookahead that means the matched key must be at the of a line ($) or immediately before a character that again isn't in the range a-z, A-Z, 0-9 or a -.

If all of your issue keys are three letters followed by four numbers followed by a dash and then another number (i.e. LLL####-#) you can use a slightly stricter regular expression:


These regular expressions are for Java applications (which most Atlassian applications are) as there are some differences between different language's implementations. There great docs on Java regular expressions if you'd like to know more, or if you want to test out other variations, you can use this neat online tool.



Thanks again Tim, I had to put an extra set of brackets around expression for Stash to accept it.


I did have to hack the Stash and Jira databases to remove the false positives; seemed helpful for triggering missed keys to be added.

Hi Mark,

You could use negative lookahead/lookbehinds, non-capturing groups and/or word boundary tokens to achieve this. I'm happy to craft you a suitable regular expression, but to be sure it suits your needs can you give a few examples of what issue keys you do want to match on and what strings you don't want to match on?



Thanks Tim,

Here are some of our commits:

CNC0021-11: Only set the abort if..

2001-CNC0012: Build version...

[maven-release-plugin] prepare release 4701-CLC0001-1.0

Only the first one is a Jira Issue. (The four digits before the Jira code denotes a component, the digits after the code are a version number [when a dot is included])


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables ROLLBAR_ACCESS_TOKEN...

195 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you