0

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

Adam Levitt
  • 10,316
  • 26
  • 84
  • 145

4 Answers4

5

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();
Anirudha
  • 32,393
  • 7
  • 68
  • 89
1

The RegExp is below. It will parse through all the lines.

(?m)BUG-([^ ]+)
Anirudha
  • 32,393
  • 7
  • 68
  • 89
ualinker
  • 745
  • 4
  • 15
0

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:

https://stackoverflow.com/a/30518972/290254

Community
  • 1
  • 1
Julius Musseau
  • 4,037
  • 23
  • 27
0

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|$))

permalink to playground

Sources worth mentioning: so-answer atlassians regex atlassioan forum

Johannes
  • 6,490
  • 10
  • 59
  • 108