2013-03-12 48 views
0

我的情况是这样的:双输入与空格替换使用正则表达式C#

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, @”</p>\n\n<p>[A-z]“); 
if (p.Success) 
{ 
    MessageBox.Show(p.Value); 
} 
+0

结果是什么?哪里出了问题?我认为有一些[Regex.Replace()](http://www.dotnetperls.com/regex-replace) – 2013-03-12 09:32:50

回答

0

您需要使用Regex.Replace

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

然而,一个更简单的方法是:

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

这也是对许多换行如何在文本或什么样的更稳健。

+0

我也试过这个表达式,但它不工作。它没有找到表达本身。 – PiggyChops 2013-03-12 09:43:30

+0

这是我的经文:1:3神说,要有光,有光。

^p ^ p

上帝看到了光明,它很好:上帝把光从黑暗中分离出来。 我想删除

merg这两行 – PiggyChops 2013-03-12 09:45:53

0

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

1

没有必要的正则表达式。尝试

line = line.Replace("\n\n", " ");