我的ant build可以接收以下任何一个输入(典型的classpath);
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 :(得分: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"/>
这种方法假设普通文件名中没有分号或冒号,但这似乎不太可能。