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
 Regular Expression String Manipulation

Author  Topic 

ksandell
Starting Member

1 Post

Posted - 2011-07-24 : 17:56:50
Using SQL 2008 and got the basics down, but...

(I can do this in python, but it too slow at 1000 rows/sec.)

I need to conduct string manipulation using regex against a column in a table, through 2 different approaches:

1) update table set [column] = ([column]<replace non-alphanumeric characters with a single space>)

2) select ([column]<replace non-alphanumeric characters with a single space>) as [alias] into new_table from table

I've worn out Google looking for this, at least I'm tired to looking through examples that don't seem to exhibit this in a simple fashion or well explained fashion.

Any simple examples would be greatly appreciated, or well explained complex examples.

Thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-24 : 18:24:09
There is no regular expression capability natively built into T-SQL. So your only choices within T-SQL are REPLACE function or STUFF function, which are very limited as stand-ins for regular expressions; they do not allow character-classes for example.

However, SQL 2005 and SQL 2008 support CLR integration, so you can create CLR functions/stored procs which can take full advantage of the .Net frame work class libraries, including the Regex class in .Net. There are several examples online, this page for example.

If you are on SQL 2008 R2, another option is to use regex capabilities from Master Data Services. This page has information and examples. I have not experimented with this approach, but this blog is by a regular contributor to SQLTeam forum.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-25 : 06:36:43
Also refer this
http://beyondrelational.com/blogs/madhivanan/archive/2009/05/11/removing-unwanted-characters.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -