gpt4 book ai didi

c# - 正则表达式上的多行

转载 作者:行者123 更新时间:2023-11-30 16:04:47 24 4
gpt4 key购买 nike

我有一个来自网站的 html 文件,我使用正则表达式搜索单词并将这些单词写入文档。我有这段文字:

<div class="scrollable " style="height: 200px;">
<div>
<p>CO-Schrank: nicht ben&ouml;tigtes ausbauen</p>
<p><strong>________________________________________________________________________</strong></p>

<p><strong>==&gt;&nbsp; wird nicht mehr ben&ouml;tigt!<br /></strong>z-B.: IUC</p>

<p>CO-Management in Gen. 2 implementieren</p>

<ol>
<li>Ausbau der PCI-Karten aus ZKA-PC in CO-PC- PC-Sys 02 TP 55, 56, 61 sind noch Profibus im ZKA-PC ==&gt; in CO-PC- PC-Sys 02 greift dann auf CO-PC f&uuml;r Datenaufzeichnung =&gt; Betrieb wieder aufnehmen</li>

<li>Ausbau der IUC</li>

<li>Testaufbau am CO-PC f&uuml;r den CO-Algorithmus und Datenspeicherung</li>

<li>Gen. 2 in CO-Management implementieren- pro Pr&uuml;fling 3 Min. (3 Min. x 48 HG x 10 Messungen)&nbsp;= 1440 Min. = 24 h- Messzeit 1-2 Min.</li>

</ol>


</div></div>

现在我想要 <div>.... </div> 中的所有文本也。我写了这段代码,但它不起作用:

Match description = Regex.Match(line, "^<div class=\"scrollable \"^(.*?)$div>", 
RegexOptions.Multiline);//multiple line

if (description.Success)
{
//Console.WriteLine(status_id.Groups[1].Value);
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\\Webasto\\csv-"+zahl+".txt");
file.WriteLine(id.Groups[1].Value + ";4;4;" + subject.Groups[1].Value + ";" + due_date.Groups[1].Value+";NULL;"+status_id.Groups[1].Value+";"//+assigned.Groups[1].Value
+";"
+priority.Groups[1].Value+";NULL;"+autor.Groups[1].Value+";0;"+created_on.Groups[1].Value+";"+start_date.Groups[1].Value+";"+done_ratio.Groups[1].Value+";"+hours.Groups[1].Value
+";NULL;"+id.Groups[1].Value+";1;2;0;"+closed.Groups[1].Value+";");
file.Close();
}

最佳答案

你对什么有误解MultiLine意思是(我不怪你,我每次使用正则表达式都要三思而后行)。 MultiLine 表示每一行(以 \n 结尾)都单独处理。

您需要 SingleLine,它将整个字符串视为一行。

旁注:使用 Regex 解析 HTML 是个坏主意。请改用合适的 HTML 解析器。

关于c# - 正则表达式上的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34512530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com