<img src='http://www.divshare.com/img/4415865-245' <img src='http://i218.photobucket.com/albums/cc151/yuuwill/html.gif' align='top'><img src='(.*?)([^gif']?')我要匹配 不是以 gif' 结尾的 上面的表达式怎么还是匹配了 'http://i218.photobucket.com/albums/cc151/yuuwill/html.gif 了啊

解决方案 »

  1.   

    [^gif] 又不是 非 gif 了,表示:除了 g i f 三个字母之外的所有字母。[] 中仅能表示一个字符,改成这样就可以了。import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test1 {
        public static void main(String[] args) {
            String str = "<img src='http://www.divshare.com/img/4415865-245'" +
                         "<img src='http://i218.photobucket.com/albums/cc151/yuuwill/html.gif' align='top'>";
            Pattern pattern = Pattern.compile("<img src='([^']*)(?<!gif)'");
            Matcher matcher = pattern.matcher(str);
            while(matcher.find()) {
                System.out.println(matcher.group());
            }
        }
    }
      

  2.   

    你的正则表达式都写错了,你的(.*?)就已经包括了html.gif在里面了
      

  3.   


    (?<!gif)这里的 ! 号是什么意思
      

  4.   

    假如一个字符串中有N个 <br>但我只匹配最后一个 <br>怎么写表达式呢
      

  5.   

    如果要问正则表达式的问题,请把具体的要求讲清楚,比如说一些示例,
    以及要达到的效果,说得越详细正则表达式的匹配完整性就越好。
    假如一个字符串中有N个  <br> 
    但我只匹配最后一个  <br> 
    怎么写表达式呢
    ——————————————————
    <br> 是连续着的呢,还是其间夹有其他的标记或者空格什么的,都没有说明。像你这个就好比在问我要写一个操作系统该怎么做啊,跟没说一样。
      

  6.   

    <img src='([^']*)(?<!gif)'不是很理解什么意思
      

  7.   

    是以<img src='开头,以不是gif结尾的字符串
      

  8.   

    (? <!gif)
    也叫做 零宽断言,意思是匹配前面不是gif的位置
      

  9.   


    也就是简单的说,如果字符串中如果有以gif结尾的,那就不匹配这个字符串
      

  10.   


    str = "aaaaaaaaaaaa<br>bbbbbbbbbbbbbbbbbbbbbbbbewe<br>dsieworiew<br>";
      

  11.   

    str = "<img src='http://i218.photobucket.com/albums/cc151/yuuwill/torrent.gif' align='absmiddle'> h<span style='font-size:1px'> </span>ttp://www.<span style='font-size:1px'> </span>jandown.<span style='font-size:1px'> </span>com/link.<span style='font-size:1px'> </span>php?ref=ShLhqsIAey</a>";
    String regx = "<([^>]*)(?<!br?)>";
    Pattern p = Pattern.compile(regx, Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(str);
    while (m.find()) {
    str = str.replace(m.group(), "");
    }
    得到的结果怎么是ttp://www.jandown.com/link.php?ref=ShLhqsIAey
    怎么把  h 也给匹配了呢
      

  12.   

    " <([^>]*)(? <!br?)>";  你这个 正则算是什么意思 呢 ?
    为什么不是你这个结构呢?
    我看了下。。就是你这个结果没有意外阿
      

  13.   

    我做了下....结果
    import java.util.regex.*;
    public class RegularONe 
    {
    public static void main(String[] args)
    {
    String resource= " <img src='http://i218.photobucket.com/albums/cc151/yuuwill/torrent.gif'" +
    " align='absmiddle'> h <span style='font-size:1px'>  " +
    "</span>ttp://www. <span style='font-size:1px'>  " +
    "</span>jandown. <span style='font-size:1px'> " +
    " </span>com/link. <span style='font-size:1px'> " +
    " </span>php?ref=ShLhqsIAey </a>";
    String regularexpression="<([^>]*)(?<!br?)>";
    Pattern pattern=Pattern.compile(regularexpression);
          Matcher matcher=pattern.matcher(resource);
          while(matcher.find())
          {
           resource=resource.replace(matcher.group(), "");
          }
          System.out.println(resource.trim());
    }}结果
    h   ttp://www.   jandown.   com/link.   php?ref=ShLhqsIAey
      

  14.   

     /**
         * 匹配匹配并提取url <br>
         * 
         * 格式: XXXX://XXX.XXX.XXX.XX/XXX.XXX?XXX=XXX
         * 
         * 匹配 : http://www.suncer.com 或news://www<br>
         * 
         * 提取(MatchResult matchResult=matcher.getMatch()): matchResult.group(0)=
         * http://www.suncer.com:8080/index.html?login=true matchResult.group(1) =
         * http matchResult.group(2) = www.suncer.com matchResult.group(3) = :8080
         * matchResult.group(4) = /index.html?login=true
         * 
         * 不匹配: c:\window
         * 
         */
        public static final String url_regexp = "(\\w+)://([^/:]+)(:\\d*)?([^#\\s]*)";