<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
|