I'd like to have a regex to match and pull out BUG-123 from this sentence:
some junk here BUG-123 My bug description goes here
Thanks
I'd like to have a regex to match and pull out BUG-123 from this sentence:
some junk here BUG-123 My bug description goes here
Thanks
You can use BUG-(\d+)
So it would be
List<string> bugNos=Regex.Matches(yourString,@"BUG-(\d+)",RegexOptions.IgnoreCase)
.Cast<Match>()
.Select(x=>x.Value).ToList();
The RegExp is below. It will parse through all the lines.
(?m)BUG-([^ ]+)
For a related StackOverflow question (Regular expression for a JIRA identifier) , I found a semi-official regex from Atlassian themselves (for Java), and I ported it to JavaScript.
Java version:
((?<!([A-Za-z]{1,10})-?)[A-Z]+-\d+)
JavaScript version (requires that everything be reversed first, though):
var jira_matcher = /\d+-[A-Z]+(?!-?[a-zA-Z]{1,10})/g
More details here:
I just looked into creating a regex for jira issues and found this entry. I found some testdata to match
VALID:
JIRA-1 BIN-10000 A-1 TACO-7133 X-88 BF-18 ABC-1 BINGO-1 BUG-123
NOT VALID:
JIRA-01 BIN-10000000 abc-123 ABCDEFGHIJKL-999 abc XY-Z-333 abcDEF-33
VALID no \s Ending
JIRA-1
And came up with (research + original work) a .net regex that should match the valid ones and not match the invalid ones:
(?<!([^\s]))([A-Z]{1,10}-[1-9][0-9]{0,6})(?=(\s|$))
Sources worth mentioning: so-answer atlassians regex atlassioan forum