You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jakob Fix <ja...@gmail.com> on 2010/05/11 11:19:33 UTC

backslash escaping in a regex

Hi, looked through the archive, but I don't think pathconvert can be
used in this case.

property file:
prop=E:\\foo\\bar

build file:
<replaceregexp file="${target.dir}/foobar.xml">
  <regexp pattern="value=&quot;[^&quot;]+&quot;"/>
  <substitution expression="value=&quot;${prop}&quot;"/>
</replaceregexp>

actual result:
value="E:foobar"

desired result:
value="E:\foo\bar"

I also tried double escaping i.e.
prop=E:\\\\foo\\\\bar

but there all backslashes disappear as well.


thanks for pointers,
Jakob.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: backslash escaping in a regex

Posted by Martin Gainty <mg...@hotmail.com>.
Hi Jacob

 

try this 

${target.dir}/foobar.xml contents contains some well known regular expression match criteria as in space between E: foo and bar:

Property=E: foo bar

 

  <replaceregexp match="\s+" replace="/" flags="g" byline="true" file="${src}/build.properties">
  </replaceregexp>


the ${target.dir}/foobar.xml replaceregexp transforms whitespace character to /:
Property=E:/foo/bar

 

hth
Martin 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité


 
Ez az üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.



 

> From: jakob.fix@gmail.com
> Date: Tue, 11 May 2010 11:19:33 +0200
> Subject: backslash escaping in a regex
> To: user@ant.apache.org
> 
> Hi, looked through the archive, but I don't think pathconvert can be
> used in this case.
> 
> property file:
> prop=E:\\foo\\bar
> 
> build file:
> <replaceregexp file="${target.dir}/foobar.xml">
> <regexp pattern="value=&quot;[^&quot;]+&quot;"/>
> <substitution expression="value=&quot;${prop}&quot;"/>
> </replaceregexp>
> 
> actual result:
> value="E:foobar"
> 
> desired result:
> value="E:\foo\bar"
> 
> I also tried double escaping i.e.
> prop=E:\\\\foo\\\\bar
> 
> but there all backslashes disappear as well.
> 
> 
> thanks for pointers,
> Jakob.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
 		 	   		  
_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4

Re: backslash escaping in a regex

Posted by Jakob Fix <ja...@gmail.com>.
Hi Stefan,

eight backslashes, wow! That means four intermediate steps to get from

\\\\\\\\ to \

I'll probably just go with the forward slashes in the property file
and pathconvert them to backslashes.

thanks a lot,
Jakob.



On Tue, May 11, 2010 at 17:29, Stefan Bodewig <bo...@apache.org> wrote:
> On 2010-05-11, Jakob Fix <ja...@gmail.com> wrote:
>
>> Hi, looked through the archive, but I don't think pathconvert can be
>> used in this case.
>
>> property file:
>> prop=E:\\foo\\bar
>
> property files and backslahes are a pain.
>
>> build file:
>> <replaceregexp file="${target.dir}/foobar.xml">
>>   <regexp pattern="value=&quot;[^&quot;]+&quot;"/>
>>   <substitution expression="value=&quot;${prop}&quot;"/>
>> </replaceregexp>
>
>> I also tried double escaping i.e.
>> prop=E:\\\\foo\\\\bar
>
>> but there all backslashes disappear as well.
>
> I'm afraid you'd need eight of them.  It may be simpler to use forward
> slashes in your property file and <pathconvert> to translate them after
> you've applied the regex.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: backslash escaping in a regex

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-05-11, Jakob Fix <ja...@gmail.com> wrote:

> Hi, looked through the archive, but I don't think pathconvert can be
> used in this case.

> property file:
> prop=E:\\foo\\bar

property files and backslahes are a pain.

> build file:
> <replaceregexp file="${target.dir}/foobar.xml">
>   <regexp pattern="value=&quot;[^&quot;]+&quot;"/>
>   <substitution expression="value=&quot;${prop}&quot;"/>
> </replaceregexp>

> I also tried double escaping i.e.
> prop=E:\\\\foo\\\\bar

> but there all backslashes disappear as well.

I'm afraid you'd need eight of them.  It may be simpler to use forward
slashes in your property file and <pathconvert> to translate them after
you've applied the regex.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org