使用c#正则表达式双击输入replace with空格
本文关键字:replace with 空格 输入 双击 正则表达式 使用 | 更新日期: 2023-09-27 18:03:41
我的情况是这样的:
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#中的正则表达式将这两行合并为一行
我用 var p = Regex.Match(line, @”</p>'n'n<p>[A-z]“);
if (p.Success)
{
MessageBox.Show(p.Value);
}
不需要正则表达式。试着
line = line.Replace("'n'n", " ");
您需要使用Regex.Replace
:
Regex.Replace(line, @"</p>'n'n<p>", " ");
但是,更简单的方法是:
Regex.Replace(line, @"(</?p>|'s)+", " ");
这对于文本中有多少换行符或哪种换行符也更健壮。
为什么需要正则表达式?您可以使用s = s.Replace("'n'n", " ");