start:
Pattern p = Pattern.compile
( "(\\[(URL)((=(((http://)|(ftp://))?)([^\\[]*))?)\\])((((http://)|(ftp://))?)([^\\[]*))(\\[(\\/URL)\\]) ",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(s);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
while(result) {
m.appendReplacement(sb, " <a href=\ " ");
if(! " ".equals(m.group(3))){
if( " ".equals(m.group(5)))
if(m.group(10)==null)
sb.append( "http:// "+m.group(9)+ "\ "> "+m.group(9)+ " </a> ");
else
sb.append( "http:// "+m.group(9)+ "\ "> "+m.group(10)+ " </a> ");
else
if(m.group(10)==null)
sb.append(m.group(5)+m.group(9)+ "\ "> "+m.group(5)+m.group(9)+ " </a> ");
else
sb.append(m.group(5)+m.group(9)+ "\ "> "+m.group(10)+ " </a> ");
}
else{
if( " ".equals(m.group(11)))
sb.append( "http:// "+m.group(10)+ "\ "> "+m.group(10)+ " </a> ");
else
sb.append(m.group(10)+ "\ "> "+m.group(10)+ " </a> ");
}
result = m.find();
}
m.appendTail(sb);
end
那位高手能给解释一下
------解决方案--------------------
应该是比较复杂的URL地址提取.
建议去看一下正则表达式(其实, 也可以直接看
java.util.regex.Matcher
java.util.regex.Pattern