本帖最后由 Myxiao7 于 2009-10-22 12:57:05 编辑

解决方案 »

  1.   

    你这个表达式写得就有问题!import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test {    public static void main(String[] args) {        
            String str = "排头兵--<img href='#' id='new'>超级链接</IMG>---两个标签的中间内容---<img href='#'>删除</img>后来居上,哈哈";
            Pattern p = Pattern.compile("(?i)<img +[^>]+>.*?</img>");
            Matcher m = p.matcher(str);
            while(m.find()) {
                System.out.println(m.group());
            }
        }
    }
      

  2.   

    Pattern.compile("(?i)<img\\b[^>]*>.*?</img>");
      

  3.   

    (?i) 模式修改符, 修改为启用 忽略大小写 模式
    类似的有(?s) 单行模式 (?m) 多行模式  等也可以写在一起 (?is) 
      

  4.   


    表示除了 > 之外所有的字符非多行模式情况下 ^ 和 $ 仅表示输入字符串的开头和结尾,多行模式下 ^ 和 $ 分别表示输入字符串每一行的行首和行尾。比如说,我们要在每行的前面加两个全角空格:public class Test {    public static void main(String[] args) {
            String str = "第一段\n第二段\n第三段";
            str = str.replaceAll("(?m)^", "##");
            System.out.println(str);
        }
    }