C.80 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 C.109: Attributes

NameTypeDescriptionDefaultRequired
propertyStringThe name of the property to set.n/aYes
overrideBooleanIf the property is already set, should we change it's value. Can be true or falsefalseNo
subjectStringThe subject to be processedn/aYes
patternStringThe regular expression pattern which is matched in the subject.n/aYes
matchStringA 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)
replaceStringA regular expression substitition pattern, which will be used to replace the given regular expression in the subject.n/aYes (unless a match is specified)
casesensitiveBooleanShould the match be case sensitivetrueNo
limitIntegerThe maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).-1No
defaultValueIntegerThe value to set the output property to, if the subject string does not match the specific regular expression.n/aNo

C.80.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...

C.80.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...

C.80.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}"/>