@Jeff Wurz comment (^\'[^\r\n]+$|''[^\r\n]+$) , , OP, " VBA".
, , , , .
!
, VBA .
Lexers vs Parsers, @SasQ answer :
3:
, (a, b), (ab, aba, bbb etd.) (, a | b). (FSA), NFA ( ) DFA ( ). , . / (()() (()())), HTML/BBcode, ... , .
2: -
, , , . . . , / . - . . x + 3 x , ..
1: -
, , (/) , , , , - , , , .
, VBA - - ( 1), - , , , , , IsInsideQuote, ... (). , litereal: , , " " False, , .
!
:
s = "abc'def ""xyz""'nutz!" 'string with apostrophes and escaped double quotes
, 3 : "abc'def ", "xyz" "'nutz!".
# 'string with apostrophes and escaped double quotes ( ) , :
static void Main(string[] args)
{
var instruction = "s = \"abc'def \"\"xyz\"\"'nutz!\" 'string with apostrophes and escaped double quotes";
int? commentStart = null;
var isInsideQuotes = false;
for (var i = 0; i < instruction.Length; i++)
{
if (instruction[i] == '"')
{
isInsideQuotes = !isInsideQuotes;
}
if (!isInsideQuotes && instruction[i] == '\'')
{
commentStart = i;
break;
}
}
if (commentStart.HasValue)
{
Console.WriteLine(instruction.Substring(commentStart.Value));
}
Console.ReadLine();
}
, , Rem :
Rem this is a legal comment
' this _
is also _
a legal comment
, \r\n , .
+ .