Skip to content

Instantly share code, notes, and snippets.

@garretmh
Created January 23, 2025 02:33
Show Gist options
  • Save garretmh/e7e86337b9e4e354153a6018687a23df to your computer and use it in GitHub Desktop.
Save garretmh/e7e86337b9e4e354153a6018687a23df to your computer and use it in GitHub Desktop.
Parse a Jira issue ID
const JIRA_ISSUE_KEY_PATTERN =
/(?<![\w-])(?<project>[A-Z][A-Z0-9_]+)-(?<issue>[1-9][0-9]*)(?![\w-])/
const JIRA_ISSUE_KEYS_PATTERN =
/(?<![\w-])(?<project>[A-Z][A-Z0-9_]+)-(?<issues>[1-9][0-9]*(?:_[1-9][0-9]*)*)(?![\w-])/
@garretmh
Copy link
Author

garretmh commented Jan 23, 2025

Explanation

  • (?<![\w-])
    Jira issue keys cannot be immediately proceeded by a word character (number, letter or underscore) or dash.
  • (?<project>[A-Z][A-Z0-9_]+)
    The first part of a Jira issue key is the project key which must start with a capital letter, followed by at least one capital letter, number or underscore.
  • -
    The project key and issue key are separated by a dash.
  • (?<issue>[1-9][0-9]*)(?![\w-])
    The second part of a Jira issue key is the issue number which must be a number without leading zeros.
  • (?![\w-])
    Jira issue keys cannot be immediately followed by a word character (number, letter or underscore) or dash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment