我有一段文字:
"text 1
Sentence 1."*"the (1)
/ðiː/
Sentence 1 Translated."
"text 2
Sentence 2."*"of (2)
/əv/
Sentence 2 Translated."
"Text 3
Sentence 3!"*"and (3)
/ænd/
Sentence 3 Translated!"
如何获取从"
到最接近的"
的除法值
将它们全部收藏起来
"text 1
Sentence 1."*"the (1)
/ðiː/
Sentence 1 Translated."
我尝试了这个,但是没有用:
"(.*?)""
答案 0 :(得分:1)
根据示例字符串判断,您需要从"
(它是一行中的第一个字符,直到行的第一个"
)中得到子字符串。
如果您将文本包含在单个变量中,例如text
,则可以使用
var results = Regex.Matches(text, @"(?sm)^("".*?"")\r?$")
.Cast<Match>()
.Select(m => m.Groups[1].Value);
请参见regex demo
模式详细信息
(?sm)
-RegexOptions.Singleline
和RegexOptions.Multiline
处于打开状态^
-一行的开头("".*?"")
-第1组:"
,0个以上的字符,但尽可能少,还有一个"
\r?
-可选的CR(因为$
在CR之前不匹配)$
-行尾。