这是我的字符串com.element.subelement
我想使用 propertyregex
将所有 .
替换为 /
,并将该输出用作目录路径。
看起来 propertyregex 就是解决这个问题的工具,但也许我错误地使用了它的 regexp
属性。
我如何使用正则表达式来查找 .
,我不想假设该字符串是由句点分隔的 3 个字母部分。也许 propertyregex 也不是完成这项工作的工具
这里是一个可行的方法,我假设包名称只有 2 个句点
<!-- set package name to folder directory -->
<propertyregex
property="current.target.dir"
input="com.element.subelement"
regexp="(.+?)\.(.+?)\.(.+?)"
replace="\1/\2/\3"
casesensitive="false" />
<echo>${current.target.dir}</echo>
最佳答案
如果我理解的话,只需将 \.
替换为 /
就可以完成您正在寻找的内容。但是,默认情况下,这只会替换一行中的第一个实例,因此您必须添加属性 global="true"
:
<propertyregex
property="current.target.dir"
input="com.element.subelement"
regexp="\."
replace="/"
global="true" />
关于regex - ant propertyregex,用指定字符串替换字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13848515/