.NET regular expressions string match replace
String match using regular expressions – VB.NET
Import Imports System.Text.RegularExpressions
'regularExpression_Match -> regular expression pattern to macth
Dim regularExpression_Match As New Regex("(.*)REGULAR EXPRESSION MATCH PATTERN(.*)")
'txtInput.txt -> Text to macth against regularExpression_Match pattern
Dim myMatch As Match = System.Text.RegularExpressions.Regex.Match(txtInput.Text, regularExpression_Match)
If myMatch.Success Then
'Do Something
End If
If Regex.IsMatch( userInputString, "\d+(\.?\d+)" ) Then
' perform some conversion and math operations here
End If
String replace using regular expressions – VB.NET
Try
'regularExpression_Replace -> regular expression pattern to replace
Dim regularExpression_Replace As New Regex("(.*)REGULAR EXPRESSION REPLACE PATTERN(.*)")
'txtInput.txt -> Text to macth and replace against
Dim txtReplacementPattern As String
txtReplacementPattern = "THIS WILL BE MY REPLACED TEXT"
'txtReplacementPattern = "$$2 $$1"
txtInput.Text = regularExpression_Replace.Replace(txtInput.Text, _
txtReplacementPattern)
Catch ex As Exception
Mess