(com.nhncorp.lucy.db.sql.ManagedDataSource:677) executing ibatis statement 'com.nhn.sapphire.cache.selectOnlyInfo'我想把com.nhn.sapphire.cache.selectOnlyInfo取出来。这样写居然不对。\'((^[\'])+?)\'

解决方案 »

  1.   

    String exe = "(com.nhncorp.lucy.db.sql.ManagedDataSource:677) executing ibatis statement 'com.nhn.sapphire.cache.selectOnlyInfo'";
    String reg = "(?<=')[^']*";Matcher mer = Pattern.compile(reg).matcher(exe);
    if (mer.find()) {
                System.out.println(mer.group());
    }
      

  2.   

    我也是最近刚学的,?表达式意思是作为判断依据,但并不作为匹配范围,具体可参见JDK文档。Special constructs (non-capturing)
    (?:X) X, as a non-capturing group
    (?idmsux-idmsux)  Nothing, but turns match flags i d m s u x on - off
    (?idmsux-idmsux:X)   X, as a non-capturing group with the given flags i d m s u x on - off
    (?=X) X, via zero-width positive lookahead
    (?!X) X, via zero-width negative lookahead
    (?<=X) X, via zero-width positive lookbehind
    (?<!X) X, via zero-width negative lookbehind
    (?>X) X, as an independent, non-capturing group
      

  3.   

    String exe = "(com.nhncorp.lucy.db.sql.ManagedDataSource:677) executing ibatis statement 'com.nhn.sapphire.cache.selectOnlyInfo'";
    String reg = "\'(.*)\'";Matcher mer = Pattern.compile(reg).matcher(exe);
    if (mer.find()) {
      System.out.println(mer.group(1));//直接用group()会带出单引号
    }
      

  4.   

    String regex = "'([^']*)'";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(str);
    while (matcher.find()) {
        System.out.println(matcher.group(1))
    }
      

  5.   


    (?<=) 这个学名叫作 positive lookbehind(肯定型逆序环视)参考这个帖子我在 4 楼的回复:http://topic.csdn.net/u/20100331/19/c0f55c3e-9338-4622-9a59-025672dfd6e4.html
      

  6.   

    当然了,也可以使用懒惰量词 *? 改成这样:// String regex = "'([^']*)'";
    String regex = "'(.*?)'";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(str);
    while (matcher.find()) {
        System.out.println(matcher.group(1));
    }
      

  7.   

    原来是我取出时少写了个参数。
    return matcher.group(1)就不会有两边的单引号了,原来是return matcher.group()