Created
January 23, 2025 02:33
-
-
Save garretmh/e7e86337b9e4e354153a6018687a23df to your computer and use it in GitHub Desktop.
Parse a Jira issue ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-])/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.