I have written a regex to match following pattern:
Any characters followed by hyphen
followed by number
followed by space
followed by an optional case insensitive keyword
followed by space
followed by any char
.
E.g.,
TXT-234 #comment anychars
TXT-234 anychars
The regular expression I have written is as follows:
(?<issueKey>^((\\s*[a-zA-Z]+-\\d+)\\s+)+)((?i)?<keyWord>#comment)?\\s+(?<comment>.*)
But the above doesn't capture the zero occurrence of '#comment', even though I have specified the '?' for the regular expression. The case 2 in the above example always fails and the case 1 succeeds.
What am I doing wrong?
#comment won't match #keyword. That is why you don't have a match try. This one it should work:
([a-zA-Z]*-\\d*\\s(((?i)#comment|#transition|#keyword)+\\s)?[a-zA-Z]*)