patindex like regex
SELECT PATINDEX(‘%[^a-z]com[^a-z]%’, ‘TechOnTheNet.com ‘);
–replace with regex
declare @sql1 as nvarchar(4000)
Declare @KeepValues as varchar(50)
Set @KeepValues = ‘%[^0-9a-z]’+SUBSTRING(@tableName, 7,20)+'[^0-9a-z]%’ –match whole word regex exp
While PatIndex(@KeepValues, @sql1) > 0
Set @sql1 = Stuff(@sql1, PatIndex(@KeepValues, @sql1)+1, len(SUBSTRING(@tableName, 7,20)), ‘[‘+@tableCatalog+’].[‘+@tableSchema+’].[‘+@tableName+’]’)