Jeroen,
  I needed to do a similar thing.  My solution was to create two new custom
functions, regex::replace and file::get-file.

  They are very simple and have no error checking :-)

<target name="initregex">
                <script language="C#" prefix="regex">
                        <code><![CDATA[
                                [Function("replace")]
                                public static string RegexReplace(string
pSource, string pSearch, string pReplace) 
                                {
                                        System.Text.RegularExpressions.Regex
re = new System.Text.RegularExpressions.Regex(pSearch,
System.Text.RegularExpressions.RegexOptions.Singleline);
                                        return re.Replace(pSource,
pReplace);
                                }
                        ]]></code>
                </script>
                
                <script language="C#" prefix="file">
                        <code><![CDATA[
                                [Function("get-file")]
                                public static string GetFile( string
pFileName ) 
                                {
                                        string s = "";
                                        using (System.IO.StreamReader sr =
new System.IO.StreamReader(pFileName)) 
                                        {
                                                s = sr.ReadToEnd();
                                        }
                                        return s;
                                }
                
                        ]]></code>
                </script>

You just have to execute the initregex task once and the functions are
available for the rest of your build file.  I usually have my tasks set a
depends on the initregex task.

It seems that there is some additional functionality comming that should do
what you need too.

John Cole

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Jeroen
Zwartepoorte
Sent: Sunday, June 27, 2004 5:14 AM
To: [EMAIL PROTECTED]
Subject: [Nant-users] using <regex> task on files


Hi,

>From looking at the documentation, it seems the <regex> task is only to
be used for retrieving data from files, not to find & replace text in a
file. There doesn't seem to be a way to do a global replace (s/blah/bla/
g) for example.

Is this correct? I need this kind of functionality for a configuration
file where the actual information required is only available at build
time. So i want to do a regex on the file:

<copy file="node.plugin.in" tofile="node.plugin"/>
<regex pattern="s/@assembly@/${assemblyfile}/g" input="node.plugin"/>
<move file="node.plugin" todir="${plugin.dir}"/>

Any ideas?

Thanks,

Jeroen



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

-------------------------------------
This email and any files transmitted with it are confidential and intended solely for 
the use of the individual or entity to whom they are addressed. If you have received 
this email in error please notify the system manager. This message contains 
confidential information and is intended only for the individual named. If you are not 
the named addressee you should not disseminate, distribute or copy this e-mail.


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to