Home
Minggo
Recent Entries 

Advertisement

Customize
8th-Aug-2006 10:22 am - 解析文本中的<IMG标签

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ss {

 public static void main(String[] arg) {
   Pattern p = Pattern.compile("<img[^>]*>",Pattern.CASE_INSENSITIVE);
   Matcher m = p.matcher("one<b>dsfasdfasd</b> <IMG sdfsd src='/www/UploadFile/200608070424195331.gif' border=0> </P></TD></TR></TBODY></TABLE> +cat two cats in the yard");
   StringBuffer sb = new StringBuffer();
   m.find();
   String img=m.group();
   Pattern p1= Pattern.compile("(src)=[\"\']?.+[\"\']?[^>]\\s",Pattern.CASE_INSENSITIVE);
   Matcher m2=p1.matcher(img);
   m2.find();
   String src=m2.group();
   System.out.println(src);
//       m.appendReplacement(sb, "dog");
//   m.appendTail(sb);
   System.out.println(sb.toString());
 
  

 }
}

Advertisement

Customize
This page was loaded Dec 7th 2009, 4:28 pm GMT.