문제

I can to use flex regular expression to find a match on "hello world" with double quote, the flex regular expression would be ["][^"\n]*["], as the result, I could get match case as hello world string without double quote. However, what happen if the string in "hello"""world", how can I use the flex regular expression to get the result as hello"""world? thanks.

올바른 솔루션이 없습니다

다른 팁

You can solve this by allowing double quotes as an alternative to any single character in the string. At the moment you have a character in the string as [^"\n]. To expand that to allow the double quotes as an alternative you write [^"\n]|\"\". A complete example flex program would look like this:

stringchar  ([^\"\r\n]|\"\")
ws           [ \t\r\n]+
%%
{ws}    printf("Whitespace: \"%s\"\n",yytext);
\"{stringchar}*\"   printf("String: %s\n",yytext);
[^ \t\r\n]+ printf("Not a string: \"%s\"\n",yytext);
%%

You should also note that flex has problems with matching adjoining tokens (see How to make lex/flex recognize tokens not separated by whitespace? ) for details. This means that "Hello"World" gets matched as "Not a String" and not a String followed by "Not a String".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top