public static final int openedHandle=0x7f010007;
        /**  Defines panel position on the screen. 
         <p>Must be one of the following constant values.</p>
<table>
<colgroup align="left" />
<colgroup align="left" />
<colgroup align="left" />
<tr><th>Constant</th><th>Value</th><th>Description</th></tr>
<tr><td><code>top</code></td><td>0</td><td> Panel placed at top of the screen. </td></tr>
<tr><td><code>bottom</code></td><td>1</td><td> Panel placed at bottom of the screen. </td></tr>
<tr><td><code>left</code></td><td>2</td><td> Panel placed at left of the screen. </td></tr>
<tr><td><code>right</code></td><td>3</td><td> Panel placed at right of the screen. </td></tr>
</table>
         */
        public static final int position=0x7f010001;大概是上面这样子,我需要匹配出 openedHandle出来即可。当然实际上我可以先判断每行有没有public static final int这个字符串,有的话就trim一下,在把=号以及后面的去掉,之后再截一下字符串就可以了。但太复杂了有需求才有进步,借此想认真的学一下正则表达式,之前自己学的那些只能匹配简单的。一复杂就不行了

解决方案 »

  1.   

    应该说我需要匹配出所有public static final int xxxxxxxxx=yyyyyyyyyy 的xxxxxxxxxxx出来
      

  2.   

    你这个问题太简单,自己去花30分钟看看,30分钟快速入门到精通正则:
    http://www.cnblogs.com/deerchao/archive/2006/08/24/zhengzhe30fengzhongjiaocheng.html
      

  3.   

    没看明白你要做什么!如果只看 public static final int 的话,那为什么只能找出 openedHandle 呢?我认为最下面的那个 position 也能匹配!PS:如果 public static final int openedHandle=0x7f010007; 位于注释里面也需要匹配么?
      

  4.   

    我那个是android工程,R文件,所以不会有注释
      

  5.   

    应该说不会把public static int xxx注释。。我还是好好学下正则吧 = =
      

  6.   

    for example
    Scanner sc = new Scanner(new FileInputStream("your_file"));
    String regex = "(?i).*?public static final int (.*?)\\s*=.*";
    Pattern p = Pattern.compile(regex);
    while (sc.hasNext()) {
        String buf = sc.nextLine();
        if (! buf.matches(regex)) continue;
        Matcher m = p.matcher(buf);
        while (m.find()) System.out.println(m.group(1));
    }正则的学习资料,LZ可以参考javadoc的Pattern类,在java.util.regex包里
      

  7.   

    用正则到是可以去出所有类似public static final int 的属性的名称。例如你上面的代码,那么用比较通用点的正则那么会取出openedHandle和position如果需要固定匹配openedHandle,那么只需要.+?\\s+openedHandle.+?这样的正则就可以筛选出openedHandle的行了
      

  8.   

    为什么大家都木有看我1楼呢。我算写出来了2楼的教程不错。
    public static final int (.+)\\s*[=]第二个组里。。虽然我不明白为什么是第二个组而不是第一个组= =