[정규식] html 엔티티제거

Sora Kim·2022년 10월 5일
0

JS / jquery

목록 보기
3/12

받은데이터

받은데이터가 < > 와 & lt; & gt; 가 섞여있어서
먼저 통일시켜준후 꺽쇠 삭제하기로 !
정규식 자료는 검색해보니 많이 있어서 적당히 나한테 필요한 애들로 사용했다

html entities 제거 js 정규식

function decode(contents) {
	if(contents != undefined && contents != null && contents != '') {
		contents = contents.replace(/<br\/>/ig,"\n");
		contents = contents.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
		contents = contents.replace(/<[^>]*>?/g,"");
	}
		return contents;
	}

적용후 출력

Product

profile
개발잘하고시풔!!!!!!!

0개의 댓글