Commits

adamv committed 814a8d2

Adding alternate RegExp support via VBScript.RegExp object.

Comments (0)

Files changed (2)

sqlserver/regex_com/DEPLOY.txt

+This script adds Regex support to SQL Server via the VBScript.RegExp object.
+To use this object, OLE Automation needs to be enabled on the server, as 
+described here:
+    http://msdn2.microsoft.com/en-us/library/ms191188.aspx
+
+with these SQL statements:
+
+sp_configure 'show advanced options', 1;
+GO
+RECONFIGURE;
+GO
+sp_configure 'Ole Automation Procedures', 1;
+GO
+RECONFIGURE;
+GO

sqlserver/regex_com/regexp_like.sql

+CREATE FUNCTION dbo.REGEXP_LIKE
+(
+	@input nvarchar(4000),
+	@pattern nvarchar(4000),
+	@caseSensitive int
+)
+RETURNS bit
+AS
+BEGIN
+	DECLARE @hresult integer
+	DECLARE @oRegexp integer
+	DECLARE @objMatches integer
+	DECLARE @objMatch integer
+	DECLARE @count integer
+	DECLARE @results bit
+	
+	EXEC @hresult = sp_OACreate 'VBScript.RegExp', @oRegexp OUTPUT
+	IF @hresult <> 0 return -1;
+
+	EXEC @hresult = sp_OASetProperty @oRegexp, 'Pattern', @pattern
+	IF @hresult <> 0 return -1;
+
+	EXEC @hresult = sp_OASetProperty @oRegexp, 'Global', false
+	IF @hresult <> 0 return -1;
+
+	IF @caseSensitive = 0 EXEC @hresult = sp_OASetProperty @oRegexp, 'IgnoreCase', 1
+	IF @hresult <> 0 return -1;
+
+	EXEC @hresult = sp_OAMethod @oRegexp, 'Test', @results OUTPUT, @input
+	IF @hresult <> 0 return -1;
+
+	EXEC @hresult = sp_OADestroy @oRegexp
+	IF @hresult <> 0 return -1;
+
+	RETURN @results
+END
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.