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]*
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.*
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.