2011-08-18 41 views
-1

我想这个字符串转换需要帮助的正则表达式除去第一BR标签

<br> 
<br class="MsoNormal" align="justify" style="MARGIN: 0cm 0cm 0pt"> 
<br class="MsoNormal" align="justify" style="MARGIN: 0cm 0cm 0pt"> 
<br> 
<br> 
<br class="MsoNormal" align="justify" style="MARGIN: 0cm 0cm 0pt"> 
Content here 

成为

Content here 

如何使用正则表达式做呢?

+1

[使用正则表达式作为一个工具来处理HTML建立了一个违反这个世界和恐惧的实体的恐惧境界。](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except- xhtml-self-contained-tags/1732454#1732454) – shesek

+2

你的问题不是完整的。你会用哪种编程语言来做这件事?您示例中的文本与您发布的标题中的问题陈述不一致。请详细说明并重新制定。 – tripleee

+1

[你不应该尝试用RegEx解析HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Bohemian

回答

0

要匹配标签,您可以使用<[^>]+>,然后根据您使用的语言,对每个匹配标签使用替换方法。

编辑:

用PHP使用:

$nohtml = preg_replace("/<[^>]+>/", "", $html); 

其中$html是包含要免费的HTML代码的字符串。

+0

你可以给我具体的例子..我的正则表达式不好 –

+1

我们还想知道用什么语言等''perl -0777 -pe'%<[^<>] *?> %% g'' – tripleee

+0

对不起,我忘了。 。我使用PHP –