Posts Tagged ‘VB.net’

.net Regular Expressions String Match Replace

.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</code>
 
<code lang="vbnet[lines]">If Regex.IsMatch( userInputString, "\d+(\.?\d+)" ) Then
    ' perform some conversion and math operations here
End If </code>
 
 
<strong>String Replace using regular expressions - VB.net</strong>
 
<code lang="vbnet">                    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

Regular Expressions in ASP.NET

Posted: July 20th, 2009
Categories: VB.net
Tags: , , ,
Comments: No Comments.