WEB/JS

JAVASCRIPT 정규식으로 text에 있는 html 태그 제거하기

나나나나나나나ㅏ나난ㄴ나ㅏ나나 2020. 8. 6. 17:06
728x90

ckeditor로 작성한 문서를 tag만 제거하고 출력하고싶을때 ?? 정규식으로 태그만 제거하자!

text = text.replace(/<br\/>/ig, "\n");
text = text.replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/ig, "");


text = text.replace(/(<([^>]+)>)/gi, "");
text = text.replace(/&nbsp;/gi,"");


console.dir(text)
return text;

 

출처

구글선생님들 🙇🏻‍♀️ 

728x90