alem0lars
alem0lars

Reputation: 690

ANT attribute in regex pattern

I'm writing an utility macro which involves checking whether a comma-separated list list contains or does not a particular value value.

<macrodef name="csvcontains">
    <attribute name="value"/>
    <attribute name="list"/>
    <attribute name="casesensitive" default="false"/>
    <sequential>
    <condition property="matched" else="false">
        <matches string="@{list}" pattern="TODO" casesensitive="@{casesensitive}"/>
    </condition>
    </sequential>
</macrodef>

I cannot get the pattern right, because I'm not sure of how to escape @{value} (and to match a comma-separated pattern).

How to build the pattern?

Upvotes: 0

Views: 1174

Answers (2)

Brian Shelden
Brian Shelden

Reputation: 73

I think your issue is that @ and { mean something in regular expressions. You can work around that by building your regex into a property, then pass the new property to your pattern attribute. He's an example:

<property name="versioning.official.build"
          value="The Daily Build"
          />
<property name="dollar.signs.mean.something.in.regexes"
          value="^${versioning.official.build}_\d"
          />
<condition property="versioning.checkin">
    <matches string="${versioning.build.name}"
             pattern="${dollar.signs.mean.something.in.regexes}"
             />
</condition>

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114767

Have you tried? It is my understanding that ant resolves all variables in a first step, so you probably don't have to escape @{value}

Upvotes: 1

Related Questions