Regex for Jira Ticket Keys

Practical regex patterns for finding Jira ticket keys like PROJ-142, with their false positives, regex engine differences, and how copy-paste can stop a key from matching.

A Jira ticket key is a short identifier made of a project key, a hyphen and an issue number, such as PROJ-142. People write regular expressions for these keys to pull ticket references out of commit messages, branch names, logs, chat exports and support emails, or to turn them into links. This review covers what such a pattern does and does not change, where it works well, where it misleads, and when matching plain exact strings is the better choice.

Is a Jira key regex suitable for your use?

A regex suits finding and extracting ticket references from free text. That includes scanning commits for keys, tagging log lines, validating that a branch name contains a key, and highlighting keys in a chat or document. Its main benefit is speed and portability. One short pattern works in editors, scripts, CI checks and most programming languages.

The main tradeoff is that a regex only checks the shape of the text. It cannot tell whether an issue exists, whether a reader has access to it, or whether a string that looks like a key is actually a ticket. A generic pattern will also match ordinary terms such as UTF-8 or SHA-256, because they have the same letters-hyphen-digits shape.

Plain text or exact matching is the better choice in three cases. Use it when you already know the specific keys you are looking for, or when false positives would cause harm, such as auto-closing or auto-linking the wrong issue. Use Jira's own search or API when you need to confirm that a key refers to a real issue.

What a Jira key regex actually changes

Matching changes nothing. A search or extraction pattern reads the stored characters and reports where a key appears. The source text is untouched. The text only changes when you use the pattern in a replace operation. Examples include wrapping each key in a link, converting it to uppercase, or stripping it from a commit subject. In those cases the stored characters do change, and you should check that the replacement keeps the key intact and readable.

Terms like reverse, mirror and font do not apply to this task. No character order is reversed and no glyphs are substituted. There is one related risk. If a key has been restyled with Unicode lookalike characters, such as fullwidth or mathematical bold letters, it may look like PROJ-142 but contain different code points, and a standard pattern will not match it.

Bidirectional display is another case where appearance and storage differ. When a key sits inside right-to-left text, the rendered position of the hyphen and number may shift on screen. The characters are still stored in logical order, though, and a regex works on that stored order, not on what the screen shows.

The shape of a Jira key

The common shape is an uppercase project key that starts with a letter, followed by a hyphen, followed by an issue number that does not start with zero. Project key rules can vary by Jira product and by administrator configuration. Some instances allow digits or underscores after the first letter, and maximum lengths are set by the platform or the administrator. The materials for this article include no instance-specific documentation, so check your own project key settings before relying on a pattern for validation.

A general-purpose pattern

\b[A-Z][A-Z0-9_]+-[1-9][0-9]*\b
  • \b requires a word boundary, so the pattern does not start in the middle of a longer word such as fooABC-1.
  • [A-Z] requires the project key to begin with an uppercase letter.
  • [A-Z0-9_]+ allows one or more further uppercase letters, digits or underscores. Narrow this to [A-Z]+ if your instance only uses letters.
  • matches a literal ASCII hyphen-minus only.
  • [1-9][0-9]* matches an issue number with no leading zero.
  • The final \b stops the match from ending partway through a longer token.

Below is an illustrative input with the matches this pattern produces. It was traced against the pattern logic, not run in a specific tool.

Input:
  Fixed PROJ-142 and OPS-7; see UTF-8 note. Not keys: proj-9, ABC-0123

Matches:
  PROJ-142
  OPS-7
  UTF-8      <- false positive: same shape as a key

No match:
  proj-9     (lowercase)
  ABC-0123   (issue number starts with 0)

Reducing false positives with an allowlist

If you know which projects matter, list their keys explicitly. This removes matches like UTF-8, ISO-8859 or COVID-19 and is the most reliable fix for false positives. The cost is maintenance: new projects have to be added to the list.

\b(?:PROJ|OPS|WEB)-[1-9][0-9]*\b

Applied to the same input, this pattern matches only PROJ-142 and OPS-7.

Branch names and lowercase input

Branch names often embed a key followed by a description, as in feature/PROJ-142-add-login. The general pattern extracts PROJ-142 from that, because a word boundary exists between the final digit and the following hyphen. People often type keys in lowercase in branch names and chat. If you need to accept that, enable case-insensitive matching and convert each match to uppercase before using it, since Jira displays keys in uppercase. Lowercase matching also widens the false-positive surface, so an allowlist becomes more valuable.

Engine differences to account for

  • Digits: in Python string patterns and in .NET by default, \d matches any Unicode decimal digit, not only 0-9. JavaScript's \d is ASCII-only. Writing [0-9] gives the same behavior everywhere.
  • Word boundaries: Python's \b is Unicode-aware for string patterns, while JavaScript's \b without the u flag treats only ASCII letters, digits and underscore as word characters. A key directly after an accented letter can therefore match in one language and not the other.
  • POSIX tools: basic and extended POSIX regular expressions do not define \d. Use [0-9]. \b is a GNU extension, so on other grep implementations consider grep -w or explicit character classes.
  • Lookaround: some engines, including Go's standard regexp package, do not support lookbehind or lookahead. The patterns in this article avoid lookaround so they stay portable.
  • Global matching: to collect every key in a text rather than just the first, use the engine's find-all mode, such as the g flag in JavaScript or findall in Python.
// JavaScript
const JIRA_KEY = /\b[A-Z][A-Z0-9_]+-[1-9][0-9]*\b/g;
const keys = text.match(JIRA_KEY) ?? [];

# Python
import re
JIRA_KEY = re.compile(r"\b[A-Z][A-Z0-9_]+-[1-9][0-9]*\b")
keys = JIRA_KEY.findall(text)

Will keys still match after copying or sharing?

Copying from rich text can quietly change a key's characters. Word processors, chat apps and web pages may substitute a non-breaking hyphen, an en dash or a minus sign for the ASCII hyphen. They may also insert zero-width characters or soft hyphens, or carry over fullwidth letters from some input methods. The key looks the same but no longer matches a pattern that expects plain ASCII. Which apps do this varies, and the materials for this article include no tests of named destinations, so treat it as a possibility to guard against rather than a documented behavior of any specific app.

A practical approach is to normalize a working copy of the text before matching and leave the original unchanged for display. NFKC normalization converts fullwidth letters and digits to ASCII. It does not turn every dash variant into a hyphen-minus, so map dashes explicitly. Leaving out the em dash avoids turning prose such as ABC—12 into a false key.

import unicodedata

DASHES = dict.fromkeys(map(ord, "\u2010\u2011\u2012\u2013\u2212"), "-")
INVISIBLE = dict.fromkeys(map(ord, "\u200b\u200c\u200d\u2060\ufeff\u00ad"), None)

def for_matching(text):
    text = unicodedata.normalize("NFKC", text)
    return text.translate(DASHES).translate(INVISIBLE)

Matching alone does not change how text reads, so it has no direct effect on screen readers, search or editing. Accessibility only becomes a concern when a replace step changes what readers see. If you turn keys into links, keep the key itself as the visible link text rather than replacing it with an icon or styled Unicode, so it stays readable, searchable and easy to copy. Whenever keys are shared for others to search or paste into Jira, a plain-text form is the safe choice: an ASCII key such as PROJ-142 with an ordinary hyphen.

Gaps to check for your own setup

  • Project key rules: allowed characters and maximum length depend on your Jira product and configuration. The materials for this article include no instance-specific documentation.
  • Existence and permissions: no regex can confirm that a matched key refers to a real issue or one the reader can open.
  • Destination behavior: no tests of specific chat apps, editors or assistive technologies were available. Test the actual tools your team uses before relying on how pasted keys behave there.