Just for the heck of it, I scratched together a template parser for T-SQL . The usage of this function is similar to the STRING_SPLIT() function, except instead of splitting a string by a delimiter character, we want to split a string according to a defined template.
SELECT * FROM dbo.Template_Split( 'Wingtip Toys (Bethel Acres, OK)', '% (%, %)' );
… will generate the following output:
Notice how the “%” wildcard character denotes how the string is split. Unlike the fancy stuff you can do with regular expressions, T-SQL wildcards don’t allow you to define capture groups, so this function is unfortunately constrained to just using “%”. I hope it will still come in handy to someone out there.
That’s it, that’s the post. Enjoy!
One thought on “T-SQL template parser”
Pingback: Parsing Templates with T-SQL – Curated SQL