Removing or Extracting Special Characters from a given String

Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 607
Suppose,we have following string as shown below:-
Here we will apply Regular Expression for pattern matching which will extract only Alpha-Numeric Characters from a given string.

Declare @regex Int,@strval varchar(100);
Set @strval = 'hello@_this-is a 1''$';
Set @regex = PatIndex('%[^a-zA-Z0-9 ]%', @strval);
While @regex > 0
Set @strval = Stuff(@strval, @regex, 1, ' ' );
Set @regex = PatIndex('%[^a-zA-Z0-9 ]%', @strval);
Select @strval as Alpha_Numeric_String;

hello this is a 1 www dotnetfunda com

Comments or Responses

Login to post response