0
我想解析多行註釋,但它總是貪婪的。貪婪的正則表達式 - 如何支持多行模式?
正則表達式:
MUL_COMMENT ("#*"(.|\n)*?"*#")
撓曲文件片段:
<DIRECTIVE>{MUL_COMMENT} {BEGIN INITIAL;
printf("mul comment for directive end:%s\n",yytext);yylval.string = strdup(yytext); return COMMENT;}
該文本文件:
#*erewrewrewr
wer*#
#set($a=7)
#*#ere
wrewrewrwe*#
的解析結果:
Node:astn=Comment,image:"#*erewrewrewr\nwer*#\n\n#set( $a=7)\n\n#*#ere\nwrewrewrwe*#"
mul comment for directive end:#*erewrewrewr
wer*#
#set($a=7)
#*#ere
wrewrewrwe*#
圖像是他的字符串匹配,顯然他是貪婪!如何解決它,請幫助我!
它運作良好,非常感謝你! – sinory