有关使用ORO对超链的过滤

<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>


        //设定超链的正则匹配表达式

        //设定以 空格(//s) 回车符(/r/n)来表示分隔

        String regexStr="(//s*)(http://)(.[^//s//r//n]*)([//s//r//n])";



        //设定对匹配表达式的字符串进行替换的字符样式

        String substitutionStr = " <A Href=/"$3/" target='_blank'>$2</A>$3 ";



        String inputString =  "";  //你自己需要替换的字符串



try{

            PatternCompiler compiler = new Perl5Compiler();

            Pattern pattern=compiler.compile(regexStr,Perl5Compiler.CASE_INSENSITIVE_MASK);

            PatternMatcher matcher = new Perl5Matcher();

            PatternMatcherInput pmi=new PatternMatcherInput(inputString);



            if(matcher.contains(pmi,pattern)){

                returnStr = Util.substitute(matcher,pattern,new Perl5Substitution(substitutionStr),inputString,Util.SUBSTITUTE_ALL);

            }

            return returnStr;

} catch(MalformedPatternException mpe){

            

}



//===================

显示结果:

如果输入的字符串为

 www http://www.77750.com gggg

转换为

 www <A Href="http://www.77750.com" target='_blank' > http://www.77750.com </A> gggg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值