I needed this functionality all over the place, so I wrote a function to
handle it. It replaces anything that matches strRegex in strInput with
strReplace. I read the file in with loadfile, do the regex-replaces,
then write the file out with echo.
<script language="CSHARP" prefix="string" >
<code>
<![CDATA[
[Function("regex-replace")]
public static string RegexReplace(string strInput, string
strRegex, string strReplace)
{
System.Text.RegularExpressions.RegexOptions options =
((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace |
System.Text.RegularExpressions.RegexOptions.Singleline) |
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string result = Regex.Replace(strInput, strRegex,
Regex.Unescape(strReplace), options);
return result;
}
]]>
</code>
</script>
e
________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steve Baker
Sent: July 29, 2005 11:34 AM
To: [email protected]
Subject: [Nant-users] regex replace
I don't see any type of functionality in nant or nantcontrib to find and
replace a string value in a file.
There is xmlpoke for xml files. How are people doing the same type of
thing for non xml files?
I wrote a task for this myself a while back, but sometimes clients
prefer to use only publicly supported tasks.
It went something like this:
<regex-replace file="filepath" find="regex expression" replace="replace
value" casesensitive="true" />
Am I missing something that exists in nant or contrib itself? Why
wouldn't something like this be included?
Thanks,
steve
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Nant-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nant-users