firen
firen

Reputation: 1424

ant propertyregex: problem with \ in paths

When I am doing something like this:

<propertyregex input="${escaped.std}" regexp=".*[/\\]data[/\\](.*)" select="\1" property="relative.std"/>

where escaped.std is ex: c:\test\data\subfolder1\subfolder2 it returns subfolder1subfolder2 (the path without the '\')

I tried to change '\' to '\\' but it just removed '\\' from the path.

Where is the problem?

Upvotes: 1

Views: 1052

Answers (2)

Rebse
Rebse

Reputation: 10377

Two solutions
first with antcontrib
second with Flaka

<project xmlns:fl="antlib:it.haefelinger.flaka">
  <taskdef resource="net/sf/antcontrib/antlib.xml"/>

  <property name="escaped.std" value="c:\test\data\subfolder1\subfolder2"/>

  <!-- solution antcontrib-1.0b3.jar -->
  <propertyregex input="${escaped.std}" regexp=".:\\(\w+\\){2}(.+)" select="\2" property="relative.std_ac"/>

  <echo>$${relative.std_ac} => ${relative.std_ac}</echo>

  <!-- solution with Flaka -->
  <fl:let>
    relative.std_fl ::= replace(property['escaped.std'],'$2','.:\\\\(\\w+\\\\){2}(.+)')
  </fl:let>

  <echo>$${relative.std_fl} => ${relative.std_fl}</echo>
</project>

output :

 [echo] ${relative.std_ac} => subfolder1\subfolder2
 [echo] ${relative.std_fl} => subfolder1\subfolder2

Upvotes: 0

wjans
wjans

Reputation: 10115

Try using the latest version of ant-contrib.

It does work fine when using ant-contrib 1.0b2 (I get the same issue when using version 0.6).

Upvotes: 2

Related Questions