| javascript 자바스크립트 html 태그 제거 |
|
|
 |
12년 전 |
javascript 자바스크립트 정규식 replace html 제거 태그 제거
내가 아는 자바스크립트로 html 제거하는 정규식 중에 가장 강력하다ㅋㅋ
정규식을 완전히 알지 못해 중복인 것도 있겠지만 잘 지워진다
/**
* 지식내용의 HTML을 제거한다.
*/
function removeHtml(text)
{
text = text.replace(/<br>/ig, "\n"); // <br>을 엔터로 변경
text = text.replace(/ /ig, " "); // 공백
// HTML 태그제거
text = text.replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/ig, "");
// shkim.add.
text = text.replace(/<(no)?script[^>]*>.*?<\/(no)?script>/ig, "");
text = text.replace(/<style[^>]*>.*<\/style>/ig, "");
text = text.replace(/<(\"[^\"]*\"|\'[^\']*\'|[^\'\">])*>/ig, "");
text = text.replace(/<\\w+\\s+[^<]*\\s*>/ig, "");
text = text.replace(/&[^;]+;/ig, "");
text = text.replace(/\\s\\s+/ig, "");
return text;
}
|
|
추천 : 657 |
추천
목록
|
|