蚂蚁的正则表达式的Andr​​oid包名 [英] ant regex for android package names

查看:960
本文介绍了蚂蚁的正则表达式的Andr​​oid包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid项目中所有的我的.java查看文件导入基于当前包的名称R档。当我在Android清单更改我的包名的名字(动态,无法通过Eclipse或任何其他IDE重构),我需要我所有的java文件的引用指向获取生成新的R文件

in my android project all of my .java view files import the R file based on the name of the current package. When I change the name of my package name in the Android Manifest (dynamically, not refactoring via Eclipse or any other IDE), I need to the references of all my java files to point to the new R file that gets generated

我通过Ant使构建脚本,但我不知道正规的前pression公约将是什么样子。

I am making a build script via Ant, but I am not sure what the regular expression convention would look like

这是需要更换的样子像这样的字符串:

The strings that need to be replaced look like this:

进口com.mysite.myapp.R;

进口com.sushiroll.california.R

这是我在我的Ant构建脚本

This is what I have in my ant build script

<replaceregexp file="src/*"
           match="import*.R"
           replace="import ${current.package}.R"
           byline="true">
        <fileset dir="src/.">
            <include name="*.java"/>
        </fileset>
</replaceregexp>

在这里我想匹配所有的字符串说导入和结束 .R

和它替换为进口$ current.package} .R

如何将我一句话,对于蚂蚁正则表达式?匹配和替换我写的只是猜测。

how would I word that for ant regex? the match and replace that I wrote were just guesses

推荐答案

您需要一批老包名称字符.R之前

You need to group old package name chars before .R

如果你知道包名

    match="import com\.mysite\.myapp\.R;"

如果你现在知道包的名字,但要ppared如果导入从不同的包R以被失败错误的进口$ P $

if you do now know package name, but be prepared to be failed for wrong imports if you import R from different packages

    match="import (.*).R;"

替换为

更换=输入$ {} current.package .R;

    <fileset dir="src">
        <include name="**/*.java"/>
    </fileset>

这篇关于蚂蚁的正则表达式的Andr​​oid包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆