Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 RegEx in TSQL

Author  Topic 

phinix
Starting Member

1 Post

Posted - 2015-04-28 : 05:26:34
Hi guys, I have this function in VB that I used in Access to replace all non-alphanumeric characters, including spaces and anything in brackets.

[CODE]Public Function charOnly3(inputString As String) As String
Dim RE As Object

Set RE = CreateObject("vbscript.regexp")

RE.Pattern = "\([^)]+\)|[^\w]|_"

RE.Global = True
charOnly3 = RE.Replace(inputString, "")

Set RE = Nothing

End Function[/CODE]Now, I moved to SQL server and I'm writing scripts to do same thing.

How can I use RegEx in TSQL?
Only thing I will do is that function.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2015-04-28 : 06:59:34
A CLR function can perform RegEx operations in SQL 2005 and higher:

https://www.simple-talk.com/sql/t-sql-programming/clr-assembly-regex-functions-for-sql-server-by-example/
Go to Top of Page
   

- Advertisement -