Removing or Extracting Special Characters from a given String

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 309
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''www.dotnetfunda@.com#$';
Set @regex = PatIndex('%[^a-zA-Z0-9 ]%', @strval);
While @regex > 0
Begin
Set @strval = Stuff(@strval, @regex, 1, ' ' );
Set @regex = PatIndex('%[^a-zA-Z0-9 ]%', @strval);
End
Select @strval as Alpha_Numeric_String;


OUTPUT
hello this is a 1 www dotnetfunda com

Comments or Responses

Login to post response