Reputation: 3082
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
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
Upvotes: 0
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.*
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.*
Upvotes: 1