论坛转贴工具中用到的正则表达式学习正则的好例子 时间:2020-05-12 人气:0 电脑教程吧-常用论坛转贴工具 电脑教程吧-常用论坛转贴工具 <script language="JavaScript"> </script> <script language=JavaScript1.2> function delnull() { var str=document.getElementById('text').value; str=str.replace(/([\s]*\r\n[\s]*){2,}/gm,"\r\n"); document.getElementById('text').value=str; } function refix() { var str=document.getElementById('text').value; str=str.replace(/([\s]*\r\n[\s]*){2,}/gm,"\r\n\r\n"); document.getElementById('text').value=str; } function url() { var str=document.getElementById('text').value; str=str.replace(/^[ ]*(http:\/\/|^mms:\/\/|rtsp:\/\/|pnm:\/\/|ftp:\/\/|mmst:\/\/|mmsu:\/\/)([^\r\n]*)$/igm,"[url]$1$2[/url]"); document.getElementById('text').value=str; } function addbr() { var str=document.getElementById('text').value; str=str.replace(/\r\n/gm,"\r\n\r\n"); document.getElementById('text').value=str; } function html_trans(str) { str = str.replace(/\r/g,""); str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,""); str = str.replace(/<script[^>]*?>([\w\W]*?)<\/script>/ig,""); if(set.fontbash.checked) { str = str.replace(/]*?display\s*?:\s*?none[^>]*?>([\w\W]*?)<\/span>/ig,""); str = str.replace(/]*?font\s*?-\s*?size\s*?:\s*(0px|0pt)[^>]*?>([\w\W]*?)<\/span>/ig,""); str = str.replace(/]+)(0px|0pt)+([^>]*)>([\w\W]*?)<\/font>/ig,""); } if(set.filtrate.checked) { str = str.replace(/[^<]*<([^>]*?)>[^<]*/ig,"<$1>"); tm=window.textfield.value; if(tm.length<1){ var arr; arr=str.match(/]+src=[" ]?([^"]+)[" ]?[^>]*>/ig); tm=arr[0].replace(/]+src=[" ]?([^"]+)[" ]?[^>]*>/ig,"$1")+"\""; i=tm.search(/\/[^\/]+"/ig); tm=tm.substr(0,i); window.textfield.value=tm+"/"; } if(tm.substr(tm.length-1,1)!="/") tm+="/"; var strtm="]+src=[\"]?("+tm+"[^\"]+)[\"]?[^>]*>"; var re = new RegExp(strtm,"ig"); str = str.replace(re,"\n[img]$1[/img]\n"); } else { if(set.stext.checked) str = str.replace(/[^<]*<([^>]*?)>[^<]*/ig,"<$1>"); if(!set.linka.checked) str = str.replace(/]+href=[" ]?([^"]+)[" ]?[^>]*>(.*?)<\/a>/ig,"[url=$1]$2[/url]"); if(!set.font_color.checked&&!set.stext.checked) str = str.replace(/]+)color=([^ >]+)([^>]*)>(.*?)<\/font>/ig,"[color=$2]$4[/color]"); if(!set.font_size.checked&&!set.stext.checked) str = str.replace(/]+)size=([^ >]+)([^>]*)>(.*?)<\/font>/ig,"[size=$2]$4[/size]"); if(!set.font_face.checked&&!set.stext.checked) str = str.replace(/]+face=([^ >]+)[^>]*>(.*?)<\/font>/ig,"[font=$1]$2[/font]"); if(!set.img.checked) str = str.replace(/]+src=[" ]?([^"]+)[" ]?[^>]*>/ig,"\n[img]$1[/img]\n"); if(!set.odj.checked){ //return str; str = str.replace(/]*?6BF52A52\-394A\-11d3\-B153\-00C04F79FAA6[^>]*?>.*]+name\s*=\s*["](url|src)["][^>]+value=[" ]?([^"]+)[" ][^>]*>.*<\/object>/ig,"\n播放视频文件在线播放\n"); str = str.replace(/]*?D27CDB6E\-AE6D\-11cf\-96B8\-444553540000[^>]*?>.*]+name\s*=\s*["](url|src)["][^>]+value=[" ]?([^"]+)[" ][^>]*>.*<\/object>/ig,"\nFlash动画在线播放\n"); str = str.replace(/]*type=["]?application\/x\-shockwave\-flash["]?[^>]*src=[" ]?([^"|^ ]+)[" ]?[^>]*>/ig,"\nFlash动画在线播放\n"); str = str.replace(/]*src=["]?([^"|^ ]+)["]?[^>]*type=["]?application\/x\-shockwave\-flash["]?[^>]*>/ig,"\nFlash动画在线播放\n"); str = str.replace(/]*?CFCDAA03\-8BE4\-11cf\-B84B\-0020AFBBCCFA[^>]*?>.*]+name\s*=\s*["](url|src)["][^>]+value=[" ]?([^"]+)[" ][^>]*>.*<\/object>/ig,"\n播放real视频流文件在线播放\n"); } if(!set.font_b.checked&&!set.stext.checked){ str = str.replace(/<([\/]?)b>/ig,"[$1b]"); str = str.replace(/<([\/]?)strong>/ig,"[$1b]");} if(!set.font_u.checked&&!set.stext.checked) str = str.replace(/<([\/]?)u>/ig,"[$1u]"); if(!set.font_i.checked&&!set.stext.checked) str = str.replace(/<([\/]?)i>/ig,"[$1i]"); str = str.replace(/ /g," "); str = str.replace(/&/g,"&"); str = str.replace(/"/g,"\""); str = str.replace(/</g,"<"); str = str.replace(/>/g,">"); } str = str.replace(/ /ig,"\n"); str = str.replace(/]*?>/ig,"\n\n"); str = str.replace(/<[^>]*?>/g,""); str = str.replace(/\[url=([^\]]+)\]\n(\[img\]\1\[\/img\])\n\[\/url\]/g,"$2"); str = str.replace(/\n+/g,"\n"); return str; } function copycode(obj){ obj.select(); objcopy=obj.createTextRange(); objcopy.execCommand("Copy"); } function trans(){ var str = ""; rtf.focus(); rtf.document.body.innerHTML = ""; rtf.document.execCommand("paste"); str = rtf.document.body.innerHTML; if(str.length == 0) { alert("剪贴版不存在超文本数据!"); return ""; } return html_trans(str); } function preview(){ var prewin=window.open("","",""); prewin.document.write(rtf.document.body.innerHTML); } function zhen(str) { strfound=str.replace(/\\/ig,"\\\\"); strfound=strfound.replace(/\[/ig,"\\["); strfound=strfound.replace(/\]/ig,"\\]"); strfound=strfound.replace(/\{/ig,"\\{"); strfound=strfound.replace(/\}/ig,"\\}"); strfound=strfound.replace(/\|/ig,"\\|"); strfound=strfound.replace(/\//ig,"\\/"); strfound=strfound.replace(/\^/ig,"\\^"); strfound=strfound.replace(/\./ig,"\\."); strfound=strfound.replace(/\*/ig,"\\*"); strfound=strfound.replace(/\?/ig,"\\?"); strfound=strfound.replace(/\+/ig,"\\+"); return strfound; } function replace_star() { var str=document.getElementById('text').value; if(!reg.checked) strfound=zhen(find_text.value); else strfound=find_text.value; var re = new RegExp(strfound,"ig"); str=str.replace(re,replace_text.value); document.getElementById('text').value=str; } </script> 电脑教程吧 » 转贴工具 电脑教程吧论坛转贴工具 </textarea> 屏蔽图片 屏蔽超链接 屏蔽对象 屏蔽文字 启用图片过滤 屏蔽字体属性 屏蔽字体颜色 屏蔽字体尺寸 屏蔽字体类型 屏蔽粗体 屏蔽斜体 屏蔽下划线 屏蔽干扰码 输入图片的基本地址 如果未指基本地址,则将自动取第一张图片的位置做基本地址。基本地址是指除文件名外的网络路径,如图片地址为:http://www.pcjc8.com/img/logo.gif ,则除去图片文件名 logo.jpg 后基本地址为:http://www.pcjc8.com/img/ 查找文字 使用正则语法 替换文字 转贴工具使用说明 1,选中你想要转贴的内容,按 Ctrl + C 将其复制 2,回到这个页面,直接点"转换剪切板数据"按钮 3,代码转化好了,点"将代码复制到剪切板"按钮 4,回到论坛发帖页面,按 Ctrl + V将代码粘贴进去 5,将你要发的帖子再编辑一下,就可以顺利发帖了 本转帖工具对于其他论坛同样有帮助,如果你觉得这个工具很有帮助,可以将本页添加到收藏页。 电脑教程吧论坛欢迎你光临:http://www.pcjc8.com 电脑教程吧论坛 <script> rtf.document.designMode="On"; </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容