Hi @ajay rawat ,
When you have a large amount of data, Guoxiong’s method does not seem to be easy.I found a function that uses regular expression fuzzy substitution,but its result is slightly different from the output you expect:
--If it exists, delete the original function
IF OBJECT_ID(N'dbo.RegexReplace') IS NOT NULL
DROP FUNCTION dbo.RegexReplace
GO
CREATE FUNCTION dbo.RegexReplace
(
@string VARCHAR(MAX),
@pattern VARCHAR(255),
@replacestr VARCHAR(255),
@IgnoreCase INT = 0
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @objRegex INT, @retstr VARCHAR(8000)
EXEC sp_OACreate 'VBScript.RegExp', @objRegex OUT
EXEC sp_OASetProperty @objRegex, 'Pattern', @pattern
EXEC sp_OASetProperty @objRegex, 'IgnoreCase', @IgnoreCase
EXEC sp_OASetProperty @objRegex, 'Global', 1
EXEC sp_OAMethod @objRegex, 'Replace', @retstr OUT, @string, @replacestr
EXECUTE sp_OADestroy @objRegex
RETURN @retstr
END
GO
--To ensure normal operation, you need to set the Ole Automation Procedures option to 1
EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'Ole Automation Procedures', 1
RECONFIGURE WITH OVERRIDE
SELECT dbo.RegexReplace(yourcol,'\=[^<>]*\;"','',1) FROM yourtable
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.