Result Method
Collapse the table of content
Expand the table of content

Match.Result Method (String)


Returns the expansion of the specified replacement pattern.

Namespace:   System.Text.RegularExpressions
Assembly:  System (in System.dll)

Public Overridable Function Result (
	replacement As String
) As String


Type: System.String

The replacement pattern to use.

Return Value

Type: System.String

The expanded version of the replacement parameter.

Exception Condition

replacement is null.


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 in Regular Expressions.

The following example replaces the hyphens that begin and end a parenthetical expression with parentheses.

Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "--(.+?)--"
      Dim replacement As String = "($1)"
      Dim input As String = "He said--decisively--that the time--whatever time it was--had come."
      For Each match As Match In Regex.Matches(input, pattern)
         Dim result As String = match.Result(replacement)
   End Sub
End Module
' The example displays the following output:
'       (decisively)
'       (whatever time it was)

The regular expression pattern --(.+?)-- is interpreted as shown in the following table.




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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2016 Microsoft