You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在不使用脚本的情况下将Ant属性转换为小写?

解决Ant属性转为小写的问题

方案1:使用Ant-contrib的<lowercase>任务

Ant-contrib提供了专门的大小写转换任务,比propertyregex更直接,适合单纯的小写转换需求:

<lowercase property="html.branding_lc" value="${html.branding}" />

当html.branding设为DEFAULT时,html.branding_lc会被正确赋值为default。

方案2:修正propertyregex的用法(若必须使用正则)

如果一定要通过propertyregex实现,需要利用其支持的函数调用特性,在替换逻辑中对捕获到的大写字母做转换:

<propertyregex property="html.branding_lc"
    input="${html.branding}"
    regexp="([A-Z])"
    replace="${toLowerCase(\1)}"
    global="true"
    override="true" />

关键要点:

  • 用捕获组([A-Z])匹配单个大写字母
  • 替换时通过toLowerCase(\1)将捕获到的内容转为小写
  • 开启global="true"确保替换所有匹配的大写字母

前置要求

确保已正确引入Ant-contrib的任务定义:

<taskdef resource="net/sf/antcontrib/antcontrib.properties" />

内容的提问来源于stack exchange,提问作者Matthew Stern

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:24:52