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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 REGEXP_REPLACE in TSQL

Author  Topic 

abacusdotcom
Posting Yak Master

133 Posts

Posted - 2014-06-18 : 15:02:04
Hi Good people.

I have challenge converting this PLSQL snippet to TSQL equivalent:

REGEXP_REPLACE(text,'(^[[:space:]]|[[:space:]]$)') 


The above helps trim out white-spaces from a text.

Do we have DIRECT conversion of the above in TSQL?

Abacus




I sign for fame not for shame but all the same, I sign my name.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-18 : 15:10:28
You can use RTRIM and LTRIM to remove trailing and leading spaces.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-06-18 : 15:18:18
T-SQL does not support regular expressions. For trimming leading and trailing spaces you can use LTRIM(RTRIM(text)). You can use regular expressions in the query window in SSMS.
Go to Top of Page

abacusdotcom
Posting Yak Master

133 Posts

Posted - 2014-06-18 : 15:31:36
Ltrim and rtrim only remove space.. what about special characters?

I sign for fame not for shame but all the same, I sign my name.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-18 : 15:38:51
quote:
Originally posted by abacusdotcom

Ltrim and rtrim only remove space.. what about special characters?



You can use the REPLACE function.

If you provide some sample data and all of the requirements, we can provide better help.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -