使用ANT propertyregex的额外空格

时间:2013-03-22 02:45:38

标签: regex ant whitespace

我一整天都在敲打这个。我有一个我从运行shell命令捕获的字符串,我需要解析该字符串并拉出文件的路径。我的工作正常,直到我尝试复制该文件...我认为我正在使用的正则表达式是在路径的前面留下一个空白字符,这会在以后引起各种麻烦。

以下是输入字符串的示例:      [echo] P4ant有输出= // perforce / dir1 / dir2 / dir3 / dir4 / dir5 / dir6 / dir7 /p4ant/p4ant-2010.1.293250.jar#1 - C:\ dir1 \ dir2 \ dir3 \ dir4 \ dir5 \ dir6 \ dir7 \ dir8 \ dir9 \ p4ant \ p4ant-2010.1.293250.jar

当我解析它时,我得到了这个:      [echo] P4ant local path = C:\ dir1 \ dir2 \ dir3 \ dir4 \ dir5 \ dir6 \ dir7 \ dir8 \ dir9 \ p4ant \ p4ant-2010.1.293250.jar

哪个看起来不错,但那里有一个额外的空间。我似乎无法摆脱它。 这是我正在使用的代码:

            <propertyregex property="p4ant.local.path"
                  input="${p4ant.have.output}"
                  regexp="([^-][^ ]+?)$"
                  select="\0"
                  casesensitive="false"
            />

我正在搜索“破折号空间”组合,它不包括输出中的破折号,但由于某种原因仍包括空格。

我在这里做错了什么? 谢谢!

1 个答案:

答案 0 :(得分:1)

\-\s <-- dash, followed by a whitespace
(.+?) <-- Anything, up to the next matching character
\s  <-- whitespace
(.+)$  <-- Anything, up to the end

所以:
    regexp="\-\s(.+?)\s(.+)$"

然后连接$ 1和$ 2(抱歉,不知道这在ANT中是如何工作的)

相关问题