Use regular expressions to replace text in the lines in a string in VB .NET

Started by nandagopal, Nov 07, 2008, 06:53 PM

Previous topic - Next topic

nandagopal

The program creates a Regex object, passing its constructor a regular expression pattern that will identify text to replace. It calls the object's Replace method, passing it the replacement pattern.


Private Sub btnGo_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnGo.Click
    Try
        Dim reg_exp As New Regex(txtPattern.Text)
        lblResult.Text = reg_exp.Replace(txtInput.Text, _
            txtReplacementPattern.Text)
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub