Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions CLR Not matching certain texts.

Status
Not open for further replies.

foreveryoung

Programmer
Sep 24, 2002
45
GB
I have created my first CLR in SQL to use regular expressions designed to match certain codes. Trouble is that I am trying to match the text HE1 in a string and keep getting a match for HE12 which is what I want to avoid. I have tried dbo.RegMatch(N'HE1[^0-9]' but this doesnot match anything. The vb.net is
Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Text.RegularExpressions

Partial Public Class UserDefinedFunctions
    <Microsoft.SqlServer.Server.SqlFunction()> _
    Public Shared Function RegMatch(ByVal REGULAREXP As String, ByVal Comments As String) As Integer
        ' Add your code here
        Dim rx As New Regex(REGULAREXP, RegexOptions.IgnoreCase) ' Or RegexOptions.IgnorePatternWhitespace)

   If rx.Match(CType(Comments, String)).Success = True Then
            Return 1
        Else
            Return 0
        End If
   End Function

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top