-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE ASSEMBLY rr FROM 'C:\Work\rr.dll' WITH PERMISSION_SET = SAFE
GO

CREATE FUNCTION REGEXREPLACE(@s NVARCHAR(50), @pat NVARCHAR(50), @rpl NVARCHAR(50))
RETURNS NVARCHAR(50)
AS
EXTERNAL NAME rr.[E.RR].RegexReplace
GO

SELECT DBO.REGEXREPLACE('XA B C 1 2 3X', '[^A-Z]', '')
GO
SELECT DBO.REGEXREPLACE('A12B34C', '\d+', '$0.0')
GO

DROP FUNCTION REGEXREPLACE
GO

DROP ASSEMBLY rr
GO
