NAnt SDK Documentation - v0.92

RegexTask Class

Sets project properties based on the evaluatuion of a regular expression.

For a list of all members of this type, see RegexTask Members.

System.Object
   NAnt.Core.Element
      NAnt.Core.Task
         NAnt.Core.Tasks.RegexTask

[Visual Basic]
<TaskName(Name:="regex")>
Public Class RegexTask
    Inherits Task
[C#]
[TaskName(Name="regex")]
public class RegexTask : Task

Thread Safety

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

Remarks

The Pattern attribute must contain one or more named grouping constructs, which represents the names of the properties to be set. These named grouping constructs can be enclosed by angle brackets (?<name>) or single quotes (?'name').

Note    In the build file, use the XML element &lt; to specify <, and &gt; to specify >.
Note    The named grouping construct must not contain any punctuation and it cannot begin with a number.

Example

Find the last word in the given string and stores it in the property lastword.

    
<regex pattern="(?'lastword'\w+)$" input="This is a test sentence" />
<echo message="${lastword}" />
    
  

Split the full filename and extension of a filename.

    
<regex pattern="^(?'filename'.*)\.(?'extension'\w+)$" input="d:\Temp\SomeDir\SomeDir\bla.xml" />
    
  

Split the path and the filename. (This checks for / or \ as the path separator).

    
<regex pattern="^(?'path'.*(\\|/)|(/|\\))(?'file'.*)$" input="d:\Temp\SomeDir\SomeDir\bla.xml" />
    
  

Results in path=d:\Temp\SomeDir\SomeDir\ and file=bla.xml.

Requirements

Namespace: NAnt.Core.Tasks

Assembly: NAnt.Core (in NAnt.Core.dll)

See Also

RegexTask Members | NAnt.Core.Tasks Namespace