大問題,我有一些內容是這樣的:在萊克斯正則表達式(詞法分析器)
author = "Marjan Mernik and Viljem Zumer",
title = "Implementation of multiple attribute grammar inheritance in the tool LISA",
year = 1999
author = "Manfred Broy and Martin Wirsing",
title = "Generalized
Heterogeneous Algebras and
Partial Interpretations",
year = 1983
author = "Ikuo Nakata and Masataka Sassa",
title = "L-Attributed LL(1)-Grammars are
LR-Attributed",
journal = "Information Processing Letters"
,我需要趕上雙引號之間家居標題。我的第一次嘗試是這樣的:
^(" "|\t)+"title"" "*=" "*"\"".+"\","
惹人第一個例子,而不是其他兩個。另一個有多條線路,這就是問題所在。我雖然要改變的東西與\n
的地方,讓多條線路,如:
^(" "|\t)+"title"" "*=" "*"\""(.|\n)+"\","
但是,這並沒有幫助,相反,它抓住一切。
比我雖然,「我要的是雙引號之間,如果我抓到的一切,直到我找到另一個"
其次,
?這樣我可以知道我是在標題或沒有結束,無論是行數,像這樣:
^(" "|\t)+"title"" "*=" "*"\""[^"\""]+","
但是,這裏有一個問題...上面的例子沒有它,但雙引號符號("
)可以在之間在標題聲明。例如:
title = "aaaaaaa \"X bbbbbb",
是的,它總是會有一個反斜槓(\
)。
任何建議來解決這個正則表達式?
爲什麼你需要lex來做到這一點?你會有解析器嗎? – LB40 2010-03-27 00:52:22