2011-08-01 75 views
0

我需要在C#中的html文件中刪除'<'和'>'之間的所有'\ n'。刪除C#中的'<' and '>'與正則表達式之間的所有' n'

我的代碼如下:

Regex.Replace(text, "(<[^<>)]*)\\n+([^><]*>$)", "\1\2"); 

但它顯然是行不通的。有什麼建議麼?

實施例:

< style=" 



"> 

詳細示例:

<td colspan="3" rowspan="2"> 
     <table cellpadding="0" cellspacing="0" class="a10" cols="13" id="t_5" lang="en-AU"> 
     <tr id="t_5_FNHR"> 
     <td class="a26" style="HEIGHT:5.00mm"> 
     <div class="r11">LAKOTA - PINK PANTHER RETURNS-V</div> 
     </td> 
     <td class="a27" style=" 



"> 
     <div class="r11">5c</div> 
     </td> 

另:

<td class="a34" style=" 



"> 
      <div class="r11">7,390.62</div> 
      </td> 
      <td class="a35" style=" 



"> 
      <div class="r11">617.81</div> 
      </td> 
      <td class="a36" style=" 



"> 
+8

哇,你究竟在做換行所有的地方呢? :/ – BoltClock

+0

你需要一直這樣做嗎?或者只是一次? –

+0

是應該在那裏的正則表達式中的第一個關閉paren? –

回答

4

一個簡單但很明顯脆性的方法是,以除去所有的換行符下一個角撐架是a >

Regex.Replace(text, @"[\r\n]+(?=[^<>]*>)", ""); 

說明:

[\r\n]+ # Match one or more CR or LF characters 
(?=  # if the following can be matched at the current position: 
[^<>]* # any number of characters except angle brackets 
>  # and one closing angle bracket 
)  # (End of lookahead). 

可能是你的情況不夠好(如果不是,正則表達式可能是不正確的工具,反正)。

+0

這幾乎可行!但是它刪除了2條換行符,並在< and >之間留下了一條新行。我希望它是<沒有新行>的東西。 – laogoat

+0

5c
laogoat

+0

可我在此附上文件? – laogoat

相關問題