<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx</link><description>Given that a recent blog of mine lamented the dangers of using xprocs, I thought it would be a good time to show some of the wonderful stuff you can do thanks to SQL Server extensibility features such as xprocs and COM objects. It’s not that xprocs or</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#416403</link><pubDate>Wed, 11 May 2005 14:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:416403</guid><dc:creator>YeYan</dc:creator><description>RePost : &lt;a rel="nofollow" target="_new" href="http://www.yeyan.cn/Database/RegularExpressionsTSQL.aspx"&gt;http://www.yeyan.cn/Database/RegularExpressionsTSQL.aspx&lt;/a&gt;</description></item><item><title>Regular Expressions in SQL Server</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#433792</link><pubDate>Wed, 29 Jun 2005 16:44:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:433792</guid><dc:creator>Adam Machanic</dc:creator><description>Can you use regular expressions in a WHERE clause? &lt;br&gt;Ken Henderson shows us how, in this recent blog...</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#439547</link><pubDate>Sat, 16 Jul 2005 06:25:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:439547</guid><dc:creator>Clifford Dibble</dc:creator><description>&lt;br&gt;This code will not run on Yukon.&lt;br&gt;&lt;br&gt;Period.&lt;br&gt;&lt;br&gt;1) 'allow updates' is a NOP since direct catalog updates are no longer allowed.&lt;br&gt;2) There is no more system_function_schema.  It was never documented anyway.&lt;br&gt;&lt;br&gt;It is very unwise to use undoc'ed internal APIs.  Don't expect code like this to port to Yukon.&lt;br&gt;&lt;br&gt;cdibble@microsoft.com&lt;br&gt;SQL Engine PM&lt;br&gt;</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#449439</link><pubDate>Tue, 09 Aug 2005 17:06:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449439</guid><dc:creator>Andriy Khwyshchun</dc:creator><description>I tried it in SQL 2k an 2005. 2k - succeeded, 2005 - got message:&lt;br&gt;Msg 15501, Level 16, State 1, Line 1&lt;br&gt;SQL Server blocked access to procedure 'sys.sp_OACreate' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see &amp;quot;Surface Area Configuration&amp;quot; in SQL Server Books Online. &lt;br&gt;</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#454424</link><pubDate>Mon, 22 Aug 2005 13:14:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:454424</guid><dc:creator>David Keaveny</dc:creator><description>Great article - this sort of functionality is very useful; a lot of the time, LIKE's selection of pattern matching just doesn't do what you need. I've already used it to identify records with garbage data in them.&lt;br&gt;&lt;br&gt;However, this approach doesn't scale too happily, as a new COM object is created per row. I found another article that builds on this idea, but reduces the number of object references that need to be created: &lt;a rel="nofollow" target="_new" href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=27205"&gt;http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=27205&lt;/a&gt;&lt;br&gt;&lt;br&gt;Working against my development database with 250K, the original query took almost 7 minutes; the revised query took less than 2 minutes, so it's a worthwhile performance improvement.</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#470642</link><pubDate>Sat, 17 Sep 2005 22:45:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:470642</guid><dc:creator>Andrew Novick</dc:creator><description>In SQL 2005 this can be done easily with the SQL-CLR.  I use a regular expression UDF as an example in a newsletter. &lt;a rel="nofollow" target="_new" href="http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N13-dot-net-clr-in-sql-server.htm"&gt;http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N13-dot-net-clr-in-sql-server.htm&lt;/a&gt; &lt;br&gt;I'm pretty sure the regular expression version is going to be faster than creating a com object.</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#662374</link><pubDate>Tue, 11 Jul 2006 18:00:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:662374</guid><dc:creator>David Mumladze</dc:creator><description>This way you don't have to create COM object multiple times...&lt;br&gt;&lt;br&gt;&lt;br&gt;set quoted_identifier on &lt;br&gt;go&lt;br&gt;set ansi_nulls on &lt;br&gt;go&lt;br&gt;&lt;br&gt;create function Regex(@rx int, @matchstring varchar(150)) returns int&lt;br&gt;as&lt;br&gt;	begin&lt;br&gt;		declare @match bit&lt;br&gt;&lt;br&gt;			-- execute &amp;quot;Test(...)&amp;quot; method&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;	exec sp_OAMethod @rx, 'Test',@match out, @matchstring&lt;br&gt;&lt;br&gt;			-- this value is greater than zero upon succesfull match&lt;br&gt;			return @match&lt;br&gt;	end&lt;br&gt;go&lt;br&gt;&lt;br&gt;&lt;br&gt;create proc RegexTest&lt;br&gt;as&lt;br&gt;	begin &lt;br&gt;		set nocount on &lt;br&gt;&lt;br&gt;		declare&lt;br&gt;			@rx int,&lt;br&gt;			@hr int,&lt;br&gt;			@pattern varchar(75)&lt;br&gt;&lt;br&gt;		set @pattern = 'DAV.*'&lt;br&gt;&lt;br&gt;		-- create Regex object and set properties &lt;br&gt;		exec @hr=sp_OACreate 'VBScript.RegExp', @rx OUT&lt;br&gt;	 &amp;nbsp; exec @hr=sp_OASetProperty @rx, 'Pattern', @pattern&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;exec @hr=sp_OASetProperty @rx, 'IgnoreCase', 1&lt;br&gt;&lt;br&gt;		&lt;br&gt;		-- execute regular expression matching pattern using Regex UDF&lt;br&gt;		select * from tableName where Regex(@rx, columnName)&amp;gt;0&lt;br&gt;		&lt;br&gt;		-- alternative select (much more inefficient than Regex)&lt;br&gt;		-- select * from tableName where columnName like 'DAV%'&lt;br&gt;	&lt;br&gt;		-- always call destroy object&lt;br&gt;		exec @hr=sp_OADestroy @rx&lt;br&gt;&lt;br&gt;	-- test&lt;br&gt;	-- exec RegexTest&lt;br&gt;		&lt;br&gt;	end&lt;br&gt;&lt;br&gt;go&lt;br&gt;set quoted_identifier on &lt;br&gt;go&lt;br&gt;set ansi_nulls on &lt;br&gt;go</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#677306</link><pubDate>Tue, 25 Jul 2006 02:58:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:677306</guid><dc:creator>Dan Mabee</dc:creator><description>we've written similar code. &amp;nbsp;especially important is the bi David Mumladze posted about factoring out the com create/destroy code if performance on medium to large tables is expected.&lt;br&gt;&lt;br&gt;something else worth noting is that with this approach indexes are useless. &amp;nbsp;since SQL doesn't know about the implementation of the function, it's hands are pretty tied and it has to hand over all values resulting in a table scan every time (unless some other criteria helps knock down the record count 1st.)&lt;br&gt;&lt;br&gt;we generally recommend to our customers that they use features like like as much as possible and only use regex when nothing else will do.&lt;br&gt;&lt;br&gt;great blog, btw. &amp;nbsp;love the bits about xp procs. &amp;nbsp;it explains a great deal about some behavior we've seen. &amp;nbsp;we've got a bunch of xp procs that work really well, but i'd still love to get the chance to convert them to clr flavor.</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#716481</link><pubDate>Thu, 24 Aug 2006 10:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:716481</guid><dc:creator>uhe2jsx@hotmail.com</dc:creator><description>funny ringtones</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#778770</link><pubDate>Sun, 01 Oct 2006 02:56:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:778770</guid><dc:creator>mike</dc:creator><description>THANKS KEN!! finally regex on sql server that I was actually able to make work!!!</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#1613604</link><pubDate>Tue, 06 Feb 2007 23:03:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1613604</guid><dc:creator>Anderson Fortaleza</dc:creator><description>&lt;p&gt;Fantastic !! Thank you so much !&lt;/p&gt;
</description></item><item><title>re: Regular Expressions in T-SQL</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#4151153</link><pubDate>Tue, 31 Jul 2007 20:40:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4151153</guid><dc:creator>Frankus</dc:creator><description>&lt;p&gt;I need help in other sentence. I want know how many if five or more letters be repetead in a word.&lt;/p&gt;
&lt;p&gt;You can help me in this??&lt;/p&gt;
</description></item><item><title>How to optimize search on an indexed field | keyongtech</title><link>http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx#9363684</link><pubDate>Thu, 22 Jan 2009 09:28:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9363684</guid><dc:creator>How to optimize search on an indexed field | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/2092955-how-to-optimize-search-on"&gt;http://www.keyongtech.com/2092955-how-to-optimize-search-on&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>