Created
May 24, 2016 19:52
-
-
Save gowon/e9aa9e8e0c9da85cdd2cdea81a796154 to your computer and use it in GitHub Desktop.
TSQL Regex Replace Scalar Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION [dbo].[RegexReplace](@input VARCHAR(MAX), @pattern VARCHAR(MAX), @replacement VARCHAR(MAX)) | |
RETURNS VARCHAR(MAX) | |
AS | |
BEGIN | |
WHILE PATINDEX(@pattern, @input) > 0 | |
SET @input = STUFF(@input, PATINDEX(@pattern, @input), 1, @replacement) | |
RETURN @input | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment