Ant: propertyregex

Ant的propertyregex任务允许对输入字符串进行正则表达式匹配,并根据匹配结果进行替换。它支持通过1, 2等引用捕获的分组,返回替换后的值。例如,可以用于提取或修改特定格式的包名或类名。" 104459186,9164190,文本预处理:从One-hot到词向量表示,"['自然语言处理', '文本表示', '机器学习', '词嵌入', '数据预处理']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码

<propertyregex property="pack.name"
		              input="package.1.name"
		              regexp="(package)\.\d\.(name)"
		              select="\1.DEF.\2"
		              casesensitive="false" />
<echo>***************${pack.name}</echo>

看到这段代码,理解了半天才明白。参照PropertyRegex

如果input的内容与regexp匹配,那么就将input的内容按照regexp里的()分组,有几个()就有几个分组,替换掉select里的\1 \2等。替换后,返回select里的值。 ( ) 标记一个子表达式的开始和结束位置。子表达式可以获取供以后使用。

Select expressions

  • \0 代表整个input的值
  • \1 代表第一个分组
  • \2 代表第二个分组
  • 等等...
所以上段代码的解释就简单了,input的值为"package.1.name"符合regexp里的正则表达式(\d 代表一个数字),并且regexp表达式里有两个(),即(package) (name),分别替换掉select里的\1 \2.所以返回值是  package.DEF.name

<pre name="code" class="html"><propertyregex property="pack.name"
				              input="package.1.name"
				              regexp="(package)\.\d\.(name)"
				              select="\0.DEF.\1.\2"
				              casesensitive="false" />
<echo>***************${pack.name}</echo>
 

运行结果:
package.1.name.DEF.package.name

Parameters

AttributeDescriptionRequired
propertyThe name of the property to set.Yes.
overrideIf the property is already set, should we change it's value. Can be true or falseNo. Defaults to false
inputThe input string to be processedYes.
regexpThe regular expression which is matched in the input string.Yes (can be specified in a <regexp> subelement).
selectA pattern which indicates what selection pattern you want in the returned value. This uses the substitution pattern syntax to indicate where to insert groupings created as a result of the regular expression match.Yes, unless a replace is specified
replaceA regular expression substitition pattern, which will be used to replace the given regular expression in the input string.Yes, unless a select is specified
casesensitiveShould the match be case sensitiveNo. default is "true".
globalShould a replacement operation be performed on the entire string, rather than just the first occuranceNo. default is false.
defaultValueThe value to set the output property to, if the input string does not match the specific regular expression.No.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值