Here's my attempt to use the named groups "display" and "mark" along with the previous described issues using only punctuation marks, each consisting of three identical characters followed by a different character (i.e. ;###Add documentation).
Here's the basic sample for a Todo that uses '#':
Code: Select all
(?<=[^#]|\A)\Q###\E(?=(?<display>[^#].*))(?=(?<mark>[^#].*))
The explanation of the expression is broken down into lettered parts:
- A. (?<=[^#]|\A)
This is a look-behind that says the phrase is either preceded by the start of the line or a non-matching character (not a '#').
B. \Q###\E
This is the phrase we are looking for, '###'.
C. (?=(?<display>[^#].*))
This does a look a look-ahead that says the phrase is followed by a non-matching character (not a '#') and matches till the end of line. It saves the what is matches and displays it in the issue's description.
D. (?=(?<mark>[^#].*))
This is identical to C above with the exception that it uses the match to mark the text in the source code highlighting.
Because I needed the display and the marked sections be identical I could only do so by using a look-ahead for each of them. Perhaps there is another way. If only one of them is needed (i.e. the default is OK for the other) then it is not required to be a look-ahead.
The expression above would match the first two lines but not the third. Both matches would display and mark the text after the '###' until the end of line.
Code: Select all
;###Must write documentation
count + adjustment ;update count ###Add additional calculations here
;######### start processing events #########
For normal 'words' instead of punctuation I would follow freak's description and mark and display only the text after the caseless match of the word 'TODO' with:
Code: Select all
(?i)\bTODO\b(?=(?<display>.*))(?=(?<mark>.*))