j_d
j_d

Reputation: 3082

Regex for PR naming convention

I want to write a regex to enforce PR naming convention, like this:

[JIRA-1234] My PR description name

Where 1234 can be any number of any length of digits, and My PR description name can be any string, as long as the length is greater than zero.

How can I achieve this? So far I have tried:

^(?=[JIRA)(.*)(?=])[a-zA-Z]*

Upvotes: 0

Views: 221

Answers (2)

Shekhar Khairnar
Shekhar Khairnar

Reputation: 2691

You can try with ^^\[JIRA\-\d+\](?:\s{1}[a-zA-Z]+)+$

\[JIRA\-\d+\] maches [JIRA-1234]

(?:\s{1}[a-zA-Z]+)+ non capturing group of(single while space followed by one or more character) at least one or more times

regex101 - demo

Upvotes: 0

The fourth bird
The fourth bird

Reputation: 163467

You can match the JIRA part followed by optional whitespace chars and start with at least a single word character and the rest of the line to not match ony whitespace chars for the description name.

^\[JIRA-\d+]\s*\w.*

Regex demo

Or match 0+ whitespace chars without a newline, and if the description can also start with another char than a word character, you can match a non whitespace char using \S

^\[JIRA-\d+][^\S\r\n]*\S.*

Regex demo

Upvotes: 1

Related Questions