I'm using FCKEditor, also have to face with this problem. I can clear the script and some on_event using the C# regex. But, that's the bad way (really bad way!) when have to loop times.. But I'm looking around for a better regex that can help me clear the loop out of the code. Is there any?
This is how I'm doing
1 private static string EncodeEvent(string text)
2 {
3 return ClearCodeEvent(text, "onBlur,onError,onFocus,onLoad,onResize,onUnload,onClick,onDblClick,onKeyDown,onKeyPress,onKeyUp,onMouseDown,onMouseMove,onMouseOut,onMouseOver,onMouseUp");
4 }
5 private static string ClearCodeEvent(string text, string filterEvent)
6 {
7 string kq = text;
8 string[] s = filterEvent.Split(',');
9 foreach (string st in s)
10 {
11 Regex r = new Regex(st + "[ ]?=[ ]?\"[^\"]+\"", RegexOptions.Multiline | RegexOptions.IgnoreCase);
12 kq = r.Replace(kq, "");
13 r = new Regex(st + "[ ]?=[ ]?\'[^\']+\'", RegexOptions.Multiline | RegexOptions.IgnoreCase);
14 kq = r.Replace(kq, "");
15 }
16 return kq;
17 }
From #11~#13: I hope thing can work with smt like (onmouseover|onmouseout|....)[ ]?=[ ]?((\"[^\"]+\")|(\'[^\']+\')) but I failed, how is the right regex for this?1 public static string ClearJSScript(string text)
2 {
3 Regex r = new Regex("((<script.*</[ ]?script>)|(<script.*/>)|(<script>)|(</script>))", RegexOptions.Multiline | RegexOptions.IgnoreCase);
4 string r1 = r.Replace(text, new MatchEvaluator(ReplaceMatchHTML));
5 return EncodeEvent(r1);
6 }
1 public static string FCKEditorHTML(string text)
2 {
3 return ClearJSScript( SafeSQLQs(text.Replace("<input type=\"image\"", "<img ")));
4 }