2012-09-09 36 views
0

過濾html標籤,我發展我的網站HTTP新聞閱讀器應用程序://www.werchelsea.com/,從原料獲得的最新消息:http://www.werchelsea.com/feed/atom/並且我能夠正確地獲取飼料並將其轉換爲字符串。現在我的主要問題是,我的飼料描述包含像html標籤數據:Android的 - 從XML(RSS/ATOM)飼料使用正則表達式

<p>It was Raul Meireles who came from the Merseyside to London to complete his move from Liverpool to Chelsea on the dead line day of the summer transfer window last year, when Chelsea failed to sign the highly-rated midfielder, Luka Modric. Chelsea were left with no other choice but to sign the Portuguese midfielder.</p> 
<p>Meireles was a regular starter under the management of Villas-Boas, he really enjoyed working under 

<a href='http://www.werchelsea.com/2012/09/05/time-to-say-good-bye-to-raul-meireles/303777_153113331443746_1122718871_n/' title='303777_153113331443746_1122718871_n'><img width="150" height="150" src="http://www.werchelsea.com/wp-content/uploads/2012/09/303777_153113331443746_1122718871_n-150x150.jpg" class="attachment-thumbnail" alt="Meireles first training session with Chelsea football club" title="303777_153113331443746_1122718871_n" /></a> 

我試圖用正則表達式替換所有這些標籤,但由於某種原因,我無法找到一個正確的RE匹配所有的html標籤類型。我用來替換是:

如果更換使用RE字符串是正確的步驟爲這個或有任何其他方式,請幫助我。

回答

0

要匹配的HTML標記(開啓或關閉),使用這個表達式:

<[^>]+?> 
+0

亞,但怎麼樣帶屬性的HTML標記? thanx! thanx! –

+0

上面的正則表達式還匹配具有屬性的標籤。它尋找一個開角尖括號,然後查找任何不是閉角尖括號(包括相等,引號等)的字符。它會在第一個關閉角度支架後終止。嘗試在http://regexpal.com/ 順便說一句,該正則表達式也符合評論。如果你不想匹配它們,請使用這個:<[^!>] +> – raffazizzi

+0

thanx man!它的工作! :) –