RandomUser
RandomUser

Reputation: 1853

How can I do SQL Server RegEx replace similar to JavaScript RegEx replace

How can perform below shown JavaScript RegEx replace in SQL Server?

var str = "$5,000";
console.log(str.replace(/[$,]/g, ""));

Output:

5000

Upvotes: 1

Views: 348

Answers (1)

Meena
Meena

Reputation: 715

Try this

declare @str money
set @str= cast(cast('$5,000' as money) as int)

Or else if you especially want to use regular expression, you can try the below,

DECLARE @Str varchar(100)
SET @Str = '$5,000' 
set @Str = STUFF(@Str, PATINDEX('%[$,]%', @Str),1, '')
select @str

Upvotes: 1

Related Questions