正则表达式 – UPPERCASE,小写,大小写Ant属性
发布时间:2020-12-14 06:34:02 所属栏目:百科 来源:网络整理
导读:在Ant中,我有一个名为“some_property”的属性,我们假设它的值为“hello”。 我正在尝试用一个大写替换该属性的值(“hello”)的文本文件中的占位符。 所以,我有这个任务: replaceregexp match="SOME_PLACE_HOLDER" replace="${some_property}" byline="t
在Ant中,我有一个名为“some_property”的属性,我们假设它的值为“hello”。
我正在尝试用一个大写替换该属性的值(“hello”)的文本文件中的占位符。 <replaceregexp match="SOME_PLACE_HOLDER" replace="${some_property}" byline="true"> 我想让它工作,就像我有这个任务一样: <replaceregexp match="SOME_PLACE_HOLDER" replace="HELLO" byline="true"> 我希望避免外部Ant任务(如Ant-Contrib),因此解决方案需要是一个纯正则表达式 – 它必须是可能的! 大写,小写和大写。 任何人都知道正确的正则表达式?
我明白你想避免使用Ant扩展,但是使用正则表达式实现解决方案的限制是有点紧张的 – 如果以下弯曲(中断?)规则太多,那么道歉。
这些天,蚂蚁有一个javascript引擎,所以在Ant xml中实现的任何似乎有问题的东西通常可以被隐藏在 在您的情况下,您将会使用some_property属性并通过上层脚本进行处理,以获取要在replaceregexp任务中使用的字符串的高位版本。 <scriptdef language="javascript" name="upper"> <attribute name="string" /> <attribute name="to" /> project.setProperty( attributes.get( "to" ),attributes.get( "string" ).toUpperCase() ); </scriptdef> <scriptdef language="javascript" name="lower"> <attribute name="string" /> <attribute name="to" /> project.setProperty( attributes.get( "to" ),attributes.get( "string" ).toLowerCase() ); </scriptdef> <scriptdef language="javascript" name="ucfirst"> <attribute name="string" /> <attribute name="to" /> var the_string = attributes.get( "string" ); project.setProperty( attributes.get( "to" ),the_string.substr(0,1).toUpperCase() + the_string.substr(1) ); </scriptdef> <scriptdef language="javascript" name="capitalize"> <attribute name="string" /> <attribute name="to" /> var s = new String( attributes.get( "string" ) ); project.setProperty( attributes.get( "to" ),s.toLowerCase().replace( /^.|sS/g,function(a) { return a.toUpperCase(); }) ); </scriptdef> 使用示例 <property name="phrase" value="the quick brown FOX jUmped oVer the laZy DOG" /> <upper string="${phrase}" to="upper" /> <lower string="${phrase}" to="lower" /> <ucfirst string="${phrase}" to="ucfirst" /> <capitalize string="${phrase}" to="capitalize" /> <echo message="upper( ${phrase} )${line.separator}= '${upper}'" /> <echo message="lower( ${phrase} )${line.separator}= '${lower}'" /> <echo message="ucfirst( ${phrase} )${line.separator}= '${ucfirst}'" /> <echo message="capitalize( ${phrase} )${line.separator}= '${capitalize}'" /> 并输出: [echo] upper( the quick brown FOX jUmped oVer the laZy DOG ) [echo] = 'THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG' [echo] lower( the quick brown FOX jUmped oVer the laZy DOG ) [echo] = 'the quick brown fox jumped over the lazy dog' [echo] ucfirst( the quick brown FOX jUmped oVer the laZy DOG ) [echo] = 'The quick brown FOX jUmped oVer the laZy DOG' [echo] capitalize( the quick brown FOX jUmped oVer the laZy DOG ) [echo] = 'The Quick Brown Fox Jumped Over The Lazy Dog' 感谢Poni和Marco Demaio为implementation of the Capitalization。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读