2015-01-05 4 views
0

내가 문자열에서 모든 HTML 태그를 제거하고 특정 (태그 및 속성을 유지)을 유지하기 위해 노력하고있어 나는이 있습니다 스트립 HTML 태그, 유지 특정

set objRegExp = new RegExp 
with objRegExp 
.Pattern = "<^((b)|(i)|(em)|(strong)|(br)|(img))>.*</.*>" 
.Global = True 
end with 

및 사용을 :

objRegExp.replace(request.form("content"), "") 

아무 것도 변경되지 않습니다.

WYSIWYG 편집기를 지원하며 xss & SQL 주입을 방지하려는 포럼을 위해이 스크립트가 필요합니다.

+0

여기에 VB6이 없습니다. 질문에 과도한 반응이 있습니다. – Bob77

답변

2

제거하려면 모든 HTML 태그 : <SPAN[^><]*>|<.SPAN[^><]*>

또는 특정 태그를 유지하기 위해 (. 예를 들어 굵게 B) :

Public Function RegexAllHtml(strValue) 
    Set RegularExpressionObject = New RegExp 
    With RegularExpressionObject 
    .Pattern = "<(.|\n)+?>" 
    .IgnoreCase = True 
    .Global = True 
    End With 
    Dim strResult: strResult = RegularExpressionObject.Replace(strValue, " ") 
    Set RegularExpressionObject = Nothing 

    RegexAllHtml = strResult 
End Function 

특정 태그 (. 예를 들어 SPAN) 당신이 뭔가를 사용할 수를 제거하려면 : <(?!/?(?:strong|b)\b)[^>]*>

BTW : 대부분의 WYSIWG 편집기를 사용하면 안전하지 않은 태그와 내용을 저장하기 전에 제거 된 태그를 구성 할 수 있습니다! 예를 들어 CKEditor를 참조하십시오 : http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent