Updated on 5/16/2015
Updated the code to deal with XML characters in the output.
Examples of how to use:
-- remove letters
SELECT * FROM dbo.PatExclude8K('abc123!', '[a-z]');
Returns: 123!
-- remove numbers
SELECT * FROM dbo.PatExclude8K('abc123!', '[0-9]');
Returns: abc!
-- only include letters and numbers
SELECT * FROM dbo.PatExclude8K('###abc123!!!', '[^0-9a-z]');
Returns: abc123
-- Remove spaces (note the spaces)
SELECT * FROM dbo.PatExclude8K('XXX 123 ZZZ', '['+char(32)+']');
Returns: XXX123ZZZ
-- only include letters and "!, ? or ."
SELECT * FROM dbo.PatExclude8K('123# What?!... ', '[^a-z!?.]')
Returns: What?!...
-- Using with make_parallel():
SELECT * FROM dbo.PatExclude8K('XXX 123 ZZZ', '['+char(32)+']')
CROSS APPLY make_parallel();