用正则表达式剪切子字符串

时间:2011-09-05 11:44:06

标签: regex ant

我想用正则表达式提取我的subversion URL的分支或标记信息。

http://192.168.1.6:8080/svn/main_repository/myCompany/myProject/branches/1.0提取:

branches-1.0

http://192.168.1.6:8080/svn/main_repository/myCompany/myProject/tags/1.0.0提取:

tags-1.0.0

注意我也想用“ - ”替换“/”。我想使用像

这样的propertiesregex任务在ant脚本中提取它
<propertyregex property="svn.Branch" input="${svn.URL}" regexp="/myproject/([^/]+)" select="\1"/>

但这仅提取

branches

tags

我需要更改以获得上述结果?

1 个答案:

答案 0 :(得分:2)

您还需要一个捕获组来映射版本号

<propertyregex property="svn.Branch" input="${svn.URL}" regexp="/myproject/([^/]+)/([^/]+)" select="\1-\2"/>
相关问题