Regular expression for receiving comments in VB.Net source code

I have syntax highlighting function in vb.net. I use regular expressions to match, for example, “! IF”, and then color it blue. This works perfectly until I tried to figure out how to make comments.

The language I write for comment can be either if the line starts with a single quote "OR, if there are two single quotes at any point in the line

'this line is a comment
!if StackOverflow = "AWESOME" ''this is also a comment

Now I know how to see if it starts with a single line ^, but I need to return the line to the end of the line so that I can color the entire green comment, not just single quotes.

You don't need the code, but here is a snippet just in case, if that helps.

    For Each pass In frmColors.lbRegExps.Items
        RegExp = System.Text.RegularExpressions.Regex.Matches(LCase(rtbMain.Text), LCase(pass))
        For Each RegExpMatch In RegExp
            rtbMain.Select(RegExpMatch.Index, RegExpMatch.Length)
            rtbMain.SelectionColor = ColorTranslator.FromHtml(frmColors.lbHexColors.Items(PassNumber))
        Next
        PassNumber += 1
    Next
+3
3

- :

^(\'[^\r\n]+)$|(''[^\r\n]+)$

( ) n ° 1

^\'[^\r\n]+$|''[^\r\n]+$

- , .

"(^'|'').*$"

, , ( ).
"", "." \r \n. .

[^\r\n] '.': . "" - .

+8

, :

"(^'|'').*$"

VonC - , . :

"(^'|'').*?$"

? * , .

+1

: REM ((\ t |). * $| $) | ^\'[^\r\n] + $|' '[^\r\n] + $

. https://code.msdn.microsoft.com/How-to-find-code-comments-9d1f7a29/

0

Source: https://habr.com/ru/post/1528987/


All Articles