在ant中,无法实现常见的字符重操作,比如截取、替换。我们可以借助ant-contrib中的propertyregex任务实现字符串的截取、替换
1、字符串的截取
比如:从字符串 root:password@127.0.0.1 中分别截取root、password、127.0.0.1三个字符串
<propertyregex property="user" input="${server}" regexp="(.*):" select="\1"/> <propertyregex property="passwd" input="${server}" regexp=":(.*)@" select="\1"/> <propertyregex property="host" input="${server}" regexp="@(.*)" select="\1"/>
2、字符串的替换
比如:替换字符串root:password@127.0.0.1为root:pwd@127.0.0.1
<propertyregex property="${svr1}" input="${svr}" regexp='password' replace="pwd"/>