Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2012
»
SQL Server 2012 - T-SQL
»
Regular expression in T-sql
26 posts, Page 1 of 3
1
2
3
»
»»
Regular expression in T-sql
Rate Topic
Display Mode
Topic Options
Author
Message
PradeepVallabh
PradeepVallabh
Posted Thursday, April 19, 2012 12:19 PM
SSC Rookie
Group: General Forum Members
Last Login: Monday, March 25, 2013 4:51 PM
Points: 41,
Visits: 447
how do we use Regular expressions in T-sql...Do we need to deploy the assemblies to sql server???
Post #1286617
Robin Sasson
Robin Sasson
Posted Friday, April 20, 2012 1:56 AM
Say Hey Kid
Group: General Forum Members
Last Login: Monday, February 18, 2013 6:17 AM
Points: 674,
Visits: 472
I'm sure that SQL Server does not support regular expressions within TSQL; I'd recommend you create a CLR.
"Be brave. Take risks. Nothing can substitute experience."
Post #1286924
Koen Verbeeck
Koen Verbeeck
Posted Wednesday, April 25, 2012 5:27 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:11 AM
Points: 9,378,
Visits: 6,473
Robin is right, CLR is the way to go.
Example:
Regular Expressions Make Pattern Matching And Data Extraction Easier
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1289743
manub22
manub22
Posted Thursday, July 26, 2012 8:43 AM
SSC Journeyman
Group: General Forum Members
Last Login: Yesterday @ 7:12 AM
Points: 82,
Visits: 559
What kinds of patterns you want to search for?
If not complex then you can use some expressions with LIKE clause.
Like if you want to search Canada ZIP codes, which are in following format 'X0X0X0', so for this you can use following query:
WHERE column_name LIKE '[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]'
Otherwise, like as other said, for complex searches you need CLR.
~manoj
sqlwithmanoj.wordpress.com
Post #1335897
CELKO
CELKO
Posted Saturday, September 15, 2012 3:16 PM
SSCommitted
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945,
Visits: 2,782
T-SQL has a limited regular expression ability in the LIKE predicate extensions. Look them up in Books on Line. Frankly, it has been strong enough for over 90% of the applications I have.
The ANSI Standard SQL has the SIMILAR TO predicate which is based on the POSIX standards. I do not know if MS will catch up
You can use CLR, but then you have to worry about maintaining every possible regular expression tools, since they are all a little different. And then there is a high cost of CLR. Avoid this kludge if you can.
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1359845
Eugene Elutin
Eugene Elutin
Posted Tuesday, September 25, 2012 3:57 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 3:09 AM
Points: 2,544,
Visits: 4,385
There are two T-SQL features which support limited regular expression functionality:
LIKE operator and PATINDEX function.
Depends of what you really need it for.
Note, the more complicated operation involved (eg. pattern match and replace), the length of the string and some other factors, then more likely that CLR solution will produce better performance. Also, CLR will allow to use RegEx objects with all available functionality.
_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
Post #1363896
Alan.B
Alan.B
Posted Thursday, September 27, 2012 11:29 PM
SSC Veteran
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:06 AM
Points: 223,
Visits: 1,137
CELKO (9/15/2012)
...And then there is a high cost of CLR. .
Hogwash. There is nothing "high cost" about a well written CLR.
Avoid this kludge if you can.
There's nothing "kludgy" about using a CLR to solve a problem that can't be solved by using T-SQL. Period.
I concur with the previous posters who suggest using a CLR for regular expressions.
-- AJB
xmlsqlninja.com
Post #1365612
bteraberry
bteraberry
Posted Friday, September 28, 2012 2:08 PM
Ten Centuries
Group: General Forum Members
Last Login: Saturday, February 23, 2013 11:07 AM
Points: 1,103,
Visits: 1,170
Microsoft invested a huge amount of effort/time/money into CLR to give us tremendous capabilities. I have been told by someone close to the SQL dev team at MS that they are tremendously disappointed by the lack of adoption to the point they significantly curtailed planned efforts to make CLR even more robust. People like CELKO spread misinformation and outright lies about CLR to prevent more widespread adoption. Why they do such a thing is a guess, but I think it has something to do with not wanting to learn new things due to being stuck in the 80's (or 60's as the case may be.) This may seem harsh, but I think it's fantastically unwarranted to lie on a forum that's supposed to help younger developers get the truth about SQL Server.
└> bt
Forum Etiquette: How to post data/code on a forum to get the best help
Post #1366106
Alan.B
Alan.B
Posted Friday, September 28, 2012 5:10 PM
SSC Veteran
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:06 AM
Points: 223,
Visits: 1,137
bteraberry (9/28/2012)
Microsoft invested a huge amount of effort/time/money into CLR to give us tremendous capabilities. I have been told by someone close to the SQL dev team at MS that they are tremendously disappointed by the lack of adoption to the point they significantly curtailed planned efforts to make CLR even more robust. People like CELKO spread misinformation and outright lies about CLR to prevent more widespread adoption. Why they do such a thing is a guess, but I think it has something to do with not wanting to learn new things due to being stuck in the 80's (or 60's as the case may be.) This may seem harsh, but I think it's fantastically unwarranted to lie on a forum that's supposed to help younger developers get the truth about SQL Server.
Well said.
I am by no means a Microsoft Koolaid drinker: Microsoft does some things I don't agree with but introducing CLRs was absolutely a great move on their part.
-- AJB
xmlsqlninja.com
Post #1366137
Jeff Moden
Jeff Moden
Posted Friday, September 28, 2012 9:04 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 7:51 PM
Points: 32,910,
Visits: 26,800
XMLSQLNinja (9/27/2012)
CELKO (9/15/2012)
...And then there is a high cost of CLR. .
Hogwash. There is nothing "high cost" about a well written CLR.
Avoid this kludge if you can.
There's nothing "kludgy" about using a CLR to solve a problem that can't be solved by using T-SQL. Period.
I concur with the previous posters who suggest using a CLR for regular expressions.
As with all else, "It Depends". In the case of RegEx CLR vs Like and PatIndex... if you can actually work it out with Like, PatIndex, or even CharIndex, it will usually be faster than making a call to a RegEx CLR. A couple of us just went through all of this on another thread a couple of months ago and the LIKE expressions blew the doors off the RegEx CLR.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1366153
« Prev Topic
|
Next Topic »
26 posts, Page 1 of 3
1
2
3
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.