2014-10-03 28 views
0

我的ant构建可以接收以下任何一种输入(典型的classpath);Ant-Contrib propertyregex通过追加字符返回所有匹配

D:\Source\Dir1 
D:\Source\Dir1; 
D:\Source\Dir1;D:\Source\Dir2 
/Source/Dir1 
/Source/Dir1: 
/Source/Dir1:/Source/Dir2 

我想通过RegEx将以上条目转换如下:

-ID:\Source\Dir1 
-ID:\Source\Dir1 
-ID:\Source\Dir1 -ID:\Source\Dir2 
-I/Source/Dir1 
-I/Source/Dir1 
-I/Source/Dir1 -I/Source/Dir2 

到目前为止,我在我的ANT有如下;

<propertyregex property="Example1-Result" input="${example}" regexp="[^${path.separator}^$]+(?:)*" replace="-I\0 " global="true"/> 

产生如下:(

-ID:\Source\Dir1 
-ID:\Source\Dir1 ; 
-ID:\Source\Dir1 ;-ID:\Source\Dir2 
-I/Source/Dir1 
-I/Source/Dir1 : 
-I/Source/Dir1 :-I/Source/Dir2 

只是想摆脱的;:从结果

+0

为什么不通过propertyregex第二次运行它来摆脱这两个字符?你期待他们出现在数据的其他地方吗? – 2014-10-05 22:52:51

+0

不,但是第二个表达是什么?只是想删除;和: – SJunejo 2014-10-06 14:16:45

+0

创建了一个显示该方法的帖子。注意它是如何使用覆盖重新使用相同的属性。 – 2014-10-07 00:39:56

回答

1

我会做两个通行证第一个说法是你的:

<propertyregex property="Example1-Result" input="${example}" 
      regexp="[^${path.separator}^$]+(?:)*" replace="-I\0 " global="true"/> 

第二个是一个简单的搜索和替换,以去除残留任何冒号或者分号:

<propertyregex property="Example1-Result" input="${Example1-Result}" 
        regexp="[:;]" replace=" " global="true" override="true"/> 

这种方法假定有不正常的文件名分号或冒号,但似乎不太可能。

+0

谢谢......这是正确的。我还得到了另一个非常简单的解决方案。见下文; ' 第一条语句将替换';和:''-I',第二个语句只是为classpath中的第一个条目添加'-I' – SJunejo 2014-10-07 01:50:46

相关问题