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