<regex> Task

# <regex>

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

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.

### Parameters

Attribute | Type | Description | Required
--- | --- | --- | ---
input | string | Represents the input for the regular expression. | True
pattern | string | Represents the regular expression to be evalued. | True
options | RegexOptions | A comma separated list of options to pass to the regex engine. The default is `None`. | False
failonerror | bool | Determines if task failure stops the build, or is just reported. The default is true. | False
if | bool | If true then the task will be executed; otherwise, skipped. The default is true. | False
unless | bool | Opposite of `if`. If false then the task will be executed; otherwise, skipped. The default is false. | False
verbose | bool | Determines whether the task should report detailed build log messages. The default is false. | False

### Examples

- 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

Assembly: NAnt.Core (0.92.4543.0)