Match::Result Method
Returns the expansion of the specified replacement pattern.
Assembly: System (in System.dll)
Parameters
- replacement
- Type: System::String
The replacement pattern to use.
| Exception | Condition |
|---|---|
| ArgumentNullException | replacement is nullptr. |
| NotSupportedException | Expansion is not allowed for this pattern. |
Whereas the Regex::Replace method replaces all matches in an input string with a specified replacement pattern, the Result method replaces a single match with a specified replacement pattern. Because it operates on an individual match, it is also possible to perform processing on the matched string before you call the Result method.
The replacement parameter is a standard regular expression replacement pattern. It can consist of literal characters and regular expression substitutions. For more information, see Substitutions.
The following example replaces the hyphens that begin and end a parenthetical expression with parentheses.
The regular expression pattern --(.+?)-- is interpreted as shown in the following table.
Pattern | Description |
|---|---|
-- | Match two hyphens. |
(.+?) | Match any character one or more times, but as few times as possible. This is the first capturing group. |
-- | Match two hyphens. |
Note that the regular expression pattern --(.+?)-- uses the lazy quantifier +?. If the greedy quantifier + were used instead, the regular expression engine would find only a single match in the input string.
The replacement string ($1) replaces the match with the first captured group, which is enclosed in parentheses.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.