0

我的情况是这样的:

1:3 And God said, Let there be light: and there was light.</p>

<p>And God saw the light, that it was good: and God divided the light from the darkness.

我想在 C# 中使用正则表达式将这 2 行与空格合并为一行

我用了

 var p = Regex.Match(line, @”&lt;/p>\n\n<p>[A-z]“);
 if (p.Success)
 {
     MessageBox.Show(p.Value);
 }
4

3 回答 3

1

不需要正则表达式。尝试

line = line.Replace("\n\n", " ");
于 2013-03-12T09:34:03.750 回答
0

您需要使用Regex.Replace

Regex.Replace(line, @"</p>\n\n<p>", " ");

但是,更简单的方法是:

Regex.Replace(line, @"(</?p>|\s)+", " ");

对于该文本中有多少换行符或哪种换行符,这也更加稳健。

于 2013-03-12T09:32:44.527 回答
0

为什么需要正则表达式?你可以简单地使用s = s.Replace("\n\n", " ");

于 2013-03-12T09:33:26.627 回答