【问题标题】:Ant-Contrib propertyregex return all matches by appending charsAnt-Contrib propertyregex 通过附加字符返回所有匹配项
【发布时间】:2014-10-03 23:17:31
【问题描述】:

我的 ant build 可以接收以下任何一种输入(典型的类路径);

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 

只想从结果中去掉 ;:

【问题讨论】:

  • 为什么不通过 propertyregex 再次运行它以摆脱这两个字符?您是否希望它们出现在数据的其他地方?
  • 不,但第二个表达式是什么?只想删除;和:
  • 创建了一篇展示这种方法的帖子。请注意它如何使用 override 来重用相同的属性。

标签: regex ant ant-contrib


【解决方案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"/>

这种方法假定普通文件名中没有分号或冒号,但这似乎不太可能。

【讨论】:

  • 谢谢...没错。我还有另一个非常简单的解决方案。见下文; &lt;propertyregex property="Example1-Result" input="${example}" regexp="\${path.separator}" replace=" -I" global="true"/&gt; &lt;property name="Example1-Result.Final" value="-I${Example1-Result}" /&gt; 第一条语句将 ; and : 替换为 `-I`,第二条语句只是为类路径中的第一个条目添加 -I
猜你喜欢
  • 1970-01-01
  • 2020-08-07
  • 2012-11-22
  • 1970-01-01
  • 2020-03-28
  • 1970-01-01
  • 1970-01-01
  • 2019-05-20
  • 1970-01-01
相关资源
最近更新 更多