<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Fun with Regular Expressions: ANT-style variable replacing in strings</title>
	<atom:link href="http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/</link>
	<description>Xtext, DSLs, Eclipse, iPhone</description>
	<lastBuildDate>Fri, 09 Jul 2010 06:39:02 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Peter</title>
		<link>http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/comment-page-1/#comment-3085</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Tue, 15 Sep 2009 13:03:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.peterfriese.de/?p=319#comment-3085</guid>
		<description>&lt;a href=&quot;#comment-3083&quot; rel=&quot;nofollow&quot;&gt;@Nick Boldt&lt;/a&gt; 
Nick, thanks for commenting. Had I been writing ANT scripts, I no doubt had used the approaches you mentioned. However, I wasn&#039;t writing ANT scripts (and writing ANT scripts wasn&#039;t an option in the particular case).

So, it&#039;s great that we now have both approaches (ANT and non-ANT) listed here so people can google them and decide whichever they need or like :-)</description>
		<content:encoded><![CDATA[<p><a href="#comment-3083" rel="nofollow">@Nick Boldt</a><br />
Nick, thanks for commenting. Had I been writing ANT scripts, I no doubt had used the approaches you mentioned. However, I wasn&#8217;t writing ANT scripts (and writing ANT scripts wasn&#8217;t an option in the particular case).</p>
<p>So, it&#8217;s great that we now have both approaches (ANT and non-ANT) listed here so people can google them and decide whichever they need or like <img src='http://www.peterfriese.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Boldt</title>
		<link>http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/comment-page-1/#comment-3083</link>
		<dc:creator>Nick Boldt</dc:creator>
		<pubDate>Mon, 14 Sep 2009 21:05:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.peterfriese.de/?p=319#comment-3083</guid>
		<description>Oh, and for resolving variables you can use Ant&#039;s built-in support for expanding properties... 

http://ant.apache.org/manual/CoreTypes/filterchain.html#expandproperties</description>
		<content:encoded><![CDATA[<p>Oh, and for resolving variables you can use Ant&#8217;s built-in support for expanding properties&#8230; </p>
<p><a href="http://ant.apache.org/manual/CoreTypes/filterchain.html#expandproperties" rel="nofollow">http://ant.apache.org/manual/CoreTypes/filterchain.html#expandproperties</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Boldt</title>
		<link>http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/comment-page-1/#comment-3082</link>
		<dc:creator>Nick Boldt</dc:creator>
		<pubDate>Mon, 14 Sep 2009 21:02:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.peterfriese.de/?p=319#comment-3082</guid>
		<description>Have you tried Ant-Contrib? With that you can just use the  task, and basically achieve this:

if (string1.matches(regex))
{ 
  string2 = string1.replace(regex,replacement)
}
else
{
  string2 = someOtherString; // or string1, whatever
}

You can also override an existing variable w/ the results of the regex replace so you don&#039;t need to create a new var to hold string2, if you only need the resulting replaced one.

Combine that with Ant-Contrib&#039;s support for  and  and you can loop through lists (strings, files, dirs), select what you want to manipulate, regex &#039;em, and be a happy camper... at least as happy as one can ever be writing code with XML syntax, anyway.

For example, see http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.dash/athena/org.eclipse.dash.commonbuilder/org.eclipse.dash.common.releng/promote.xml?view=annotate&amp;root=Technology_Project, line 130.</description>
		<content:encoded><![CDATA[<p>Have you tried Ant-Contrib? With that you can just use the  task, and basically achieve this:</p>
<p>if (string1.matches(regex))<br />
{<br />
  string2 = string1.replace(regex,replacement)<br />
}<br />
else<br />
{<br />
  string2 = someOtherString; // or string1, whatever<br />
}</p>
<p>You can also override an existing variable w/ the results of the regex replace so you don&#8217;t need to create a new var to hold string2, if you only need the resulting replaced one.</p>
<p>Combine that with Ant-Contrib&#8217;s support for  and  and you can loop through lists (strings, files, dirs), select what you want to manipulate, regex &#8216;em, and be a happy camper&#8230; at least as happy as one can ever be writing code with XML syntax, anyway.</p>
<p>For example, see <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.dash/athena/org.eclipse.dash.commonbuilder/org.eclipse.dash.common.releng/promote.xml?view=annotate&amp;root=Technology_Project" rel="nofollow">http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.dash/athena/org.eclipse.dash.commonbuilder/org.eclipse.dash.common.releng/promote.xml?view=annotate&amp;root=Technology_Project</a>, line 130.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/comment-page-1/#comment-3080</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 11 Sep 2009 14:55:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.peterfriese.de/?p=319#comment-3080</guid>
		<description>&lt;a href=&quot;#comment-3079&quot; rel=&quot;nofollow&quot;&gt;@Dennis&lt;/a&gt; 
Dennis, I tried to reproduce your issue. Here are the properties:
propertyA=SomeValue[$1]
propertyB=${propertyA}.SomeOtherValue: $1
listofThings=${propertyA}, ${propertyB}, constantValue&quot;

and here is the output:

SomeValue[propertyA], SomeValue[propertyA].SomeOtherValue: propertyB, constantValue

Looks as intended, or am I missing something? If so, please feel free to post a complete code example :-)</description>
		<content:encoded><![CDATA[<p><a href="#comment-3079" rel="nofollow">@Dennis</a><br />
Dennis, I tried to reproduce your issue. Here are the properties:<br />
propertyA=SomeValue[$1]<br />
propertyB=${propertyA}.SomeOtherValue: $1<br />
listofThings=${propertyA}, ${propertyB}, constantValue&#8221;</p>
<p>and here is the output:</p>
<p>SomeValue[propertyA], SomeValue[propertyA].SomeOtherValue: propertyB, constantValue</p>
<p>Looks as intended, or am I missing something? If so, please feel free to post a complete code example <img src='http://www.peterfriese.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://www.peterfriese.de/fun-with-regular-expressions-ant-style-variable-replacing-in-strings/comment-page-1/#comment-3079</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Fri, 11 Sep 2009 12:28:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.peterfriese.de/?p=319#comment-3079</guid>
		<description>Your version do have a bug which will not correctly replace &quot;$1&quot;.

-- quote from JavaDoc --
The replacement string may contain references to subsequences captured during the previous match: Each occurrence of $g will be replaced by the result of evaluating group(g). The first number after the $ is always treated as part of the group reference. Subsequent numbers are incorporated into g if they would form a legal group reference. Only the numerals &#039;0&#039; through &#039;9&#039; are considered as potential components of the group reference. If the second group matched the string &quot;foo&quot;, for example, then passing the replacement string &quot;$2bar&quot; would cause &quot;foobar&quot; to be appended to the string buffer. A dollar sign ($) may be included as a literal in the replacement string by preceding it with a backslash (\$).
--

The missing piece is that the replacement string has to be replaced &quot;$&quot; -&gt;&quot;\$&quot; before the appendReplacement.


It is stupid.... I have to do another replace in order to do a replace.
Why don&#039;t JDK provide a nice and friendly API?</description>
		<content:encoded><![CDATA[<p>Your version do have a bug which will not correctly replace &#8220;$1&#8243;.</p>
<p>&#8211; quote from JavaDoc &#8211;<br />
The replacement string may contain references to subsequences captured during the previous match: Each occurrence of $g will be replaced by the result of evaluating group(g). The first number after the $ is always treated as part of the group reference. Subsequent numbers are incorporated into g if they would form a legal group reference. Only the numerals &#8216;0&#8242; through &#8216;9&#8242; are considered as potential components of the group reference. If the second group matched the string &#8220;foo&#8221;, for example, then passing the replacement string &#8220;$2bar&#8221; would cause &#8220;foobar&#8221; to be appended to the string buffer. A dollar sign ($) may be included as a literal in the replacement string by preceding it with a backslash (\$).<br />
&#8211;</p>
<p>The missing piece is that the replacement string has to be replaced &#8220;$&#8221; -&gt;&#8221;\$&#8221; before the appendReplacement.</p>
<p>It is stupid&#8230;. I have to do another replace in order to do a replace.<br />
Why don&#8217;t JDK provide a nice and friendly API?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
