2016-12-16 2 views
0

Google Apps Script의 콘텐츠에서 HTML 태그를 스트라이프하는 방법을 찾고 있습니다. 지금은 HTML 구문 분석에 이러한 기능을 사용하고 들어Google Apps Script의 스트라이프 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("<[^>]*>", ""); 
관련 문제