2016-12-16 12 views
0

我正在尋找使用緊固件來從Google Apps腳本中的內容中分離HTML標記的方法。在Google Apps腳本中條帶化HTML標記

現在我使用這些功能HTML解析:

function getTextFromHtml(body) { 
    return getTextFromNode(Xml.parse(body, true).getElement()); 
} 

function getTextFromNode(x) { 
switch(x.toString()) { 
    case 'XmlText': return x.toXmlString(); 
    case 'XmlElement': return x.getNodes().map(getTextFromNode).join(''); 
    default: return ''; 
} 
} 

但對於大的HTML的這種方式是如此低效。

樣本HTML內容:http://pastebin.com/FmB4hvN2

任何想法?

回答

1

這將刪除輸入中的所有標籤。

var text = html.replace(/<[^>]+>/g, ""); 
+0

你是對的!謝謝! – Labradorcode

1

如果您要更換的內容始終包裹着<和>,你可以做

Regex rgx = new Regex(someString); 
string result = rgx.Replace("<[^>]*>", "");