RegexReplace Class

MSBuild

Task to replace portions of strings within the Input list Output list contains all the elements of the Input list after performing the Regex Replace.


Namespace: MSBuild.Community.Tasks
Assembly: MSBuild.Community.Tasks (in MSBuild.Community.Tasks.dll)

Syntax

Visual Basic (Declaration)
Public Class RegexReplace
    Inherits RegexBase
C#
public class RegexReplace : RegexBase
C++
ref class RegexReplace : RegexBase
J#
public class RegexReplace extends RegexBase
JScript
public class RegexReplace extends RegexBase

Example

1st example replaces first occurance of "foo." with empty string 2nd example replaces occurance of "foo." after character 6 with "oop." string

 Copy Code
            <ItemGroup>
               <TestGroup Include="foo.my.foo.foo.test.o" />
               <TestGroup Include="foo.my.faa.foo.test.a" />
               <TestGroup Include="foo.my.fbb.foo.test.b" />
               <TestGroup Include="foo.my.fcc.foo.test.c" />
               <TestGroup Include="foo.my.fdd.foo.test.d" />
               <TestGroup Include="foo.my.fee.foo.test.e" />
               <TestGroup Include="foo.my.fff.foo.test.f" />
            </ItemGroup>
            <Target Name="Test">
               <Message Text="Input:&#xA;@(TestGroup, '&#xA;')"/>
               <!-- Replaces first occurance of "foo." with empty string-->
               <RegexReplace Input="@(TestGroup)" Expression="foo\." Replacement="" Count="1">
                  <Output ItemName ="ReplaceReturn1" TaskParameter="Output" />
               </RegexReplace>
               <Message Text="&#xA;Output Replace 1:&#xA;@(ReplaceReturn1, '&#xA;')" />
               <!-- Replaces occurance of "foo." after character 6 with "oop." string-->
               <RegexReplace Input="@(TestGroup)" Expression="foo\." Replacement="oop" Startat="6">
                  <Output ItemName ="ReplaceReturn2" TaskParameter="Output" />
               </RegexReplace>
               <Message Text="&#xA;Output Replace 2:&#xA;@(ReplaceReturn2, '&#xA;')" />
            </Target>
            

Inheritance Hierarchy

System.Object
   Microsoft.Build.Utilities.Task
      MSBuild.Community.Tasks.RegexBase
         MSBuild.Community.Tasks.RegexReplace

Thread Safety

Public static (Shared in Visual Basic)staticShared members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

See Also

Syntax based on .NET Framework version 2.0.
Documentation version 1.0.0.0.