Last post Feb 19, 2018 06:47 AM by Brando ZWZ
Feb 18, 2018 04:07 PM|Shashank Srivastava|LINK
Problem Statement: I am trying to replace the numbers enclosed between parentheses in the input string using the below mentioned regex. But its not working for me.
However i have tested the regex on the following link: https://regex101.com/. It works there, not sure why it's not working in SQL Server for me.
Please guide me what am i doing wrong here. Any help will be appreciable.
Input String: sd (1) (2)(35)
Expected Output: sd
Used Regex: \([0-9]*\)
DECLARE @a varchar(20) = 'sd (1)', @b varchar(20) ;
SELECT @b = REPLACE(@a, '\([0-9]*\)', '');
Feb 19, 2018 06:47 AM|Brando ZWZ|LINK
Hi Shashank Srivastava,
As far as I know, we couldn't use regex in sql query.
If you want to use regex replace, I suggest you could consider using some third party library. Like Eval SQL.NET
It contains regex.replace function.