Please help me write a PATINDEX or LIKE statement to match characters other than:
- A-Z, 0-9, hyphen (-), period (.), underscore (_), and tilde (~)
I plan to use this in a scalar UDF with an nvarchar(200) input, which processes the input by:
- Replace the non-matching characters with hyphen (-)
- Replace two occurences of hyphen (–) with single (-)
- Removes leading and trailing hypens (-)
- Returns the processed input
This will be used to create part of an SEO-friendly URL e.g. /my-seo-friendly-url-1. I am very confident in doing this UDF, apart from the pattern-matching part. Regex-like stuff confuses me! Please help.
Thanks for your help in advance.
Probably best done in your application but
should do it in TSQL