代码
<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
Attribute | Description | Required |
---|---|---|
property | The name of the property to set. | Yes. |
override | If the property is already set, should we change it's value. Can be true or false | No. Defaults to false |
input | The input string to be processed | Yes. |
regexp | The regular expression which is matched in the input string. | Yes (can be specified in a <regexp> subelement). |
select | A 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 |
replace | A regular expression substitition pattern, which will be used to replace the given regular expression in the input string. | Yes, unless a select is specified |
casesensitive | Should the match be case sensitive | No. default is "true". |
global | Should a replacement operation be performed on the entire string, rather than just the first occurance | No. default is false . |
defaultValue | The value to set the output property to, if the input string does not match the specific regular expression. | No. |