B.45 PropertyRegexTask

Performs regular expression operations on an subject string, and sets the results to a property. There are two different operations that can be performed:

Table B.47: Attributes

NameTypeDescriptionDefaultRequired
property String The name of the property to set.n/aYes
override Boolean If the property is already set, should we change it's value. Can be true or false falseNo
subject String The subject to be processedn/aYes
pattern String The regular expression pattern which is matched in the subject.n/aYes
match String A pattern which indicates what match 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. n/aYes (unless a replace is specified)
replace String A regular expression substitition pattern, which will be used to replace the given regular expression in the subject. n/aYes (unless a match is specified)
casesensitive Boolean Should the match be case sensitivetrueNo
limit Integer The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit). -1No
defaultValue Integer The value to set the output property to, if the subject string does not match the specific regular expression. n/aNo

B.45.1 Match expressions

Expressions are matched in a the same syntax as a regular expression substitution pattern.

  • $0 indicates the entire property name (default).

  • $1 indicates the first grouping

  • $2 indicates the second grouping

  • etc...

B.45.2 Replace

It is important to note that when doing a "replace" operation, if the subject string does not match the regular expression, then the property is not set. You can change this behavior by supplying the "defaultValue" attribute. This attribute should contain the value to set the property to in this case.

  • $0 indicates the entire property name (default).

  • $1 indicates the first grouping

  • $2 indicates the second grouping

  • etc...

B.45.3 Example

<propertyregex property="pack.name"
    subject="package.ABC.name"
    pattern="package\.([^.]*)\.name"
    match="$1"
    casesensitive="false"
    defaultvalue="test1"/>

<echo message="${pack.name}"/>

<propertyregex property="pack.name"
    override="true"
    subject="package.ABC.name"
    pattern="(package)\.[^.]*\.(name)"
    replace="$1.DEF.$2"
    casesensitive="false"
    defaultvalue="test2"/>

<echo message="${pack.name}"/>