Did you know that you can use Regular Expressions in tSQL? Welp, you certainly can. The key is to use the LINK operator and the [square brackets] to indicate patterns.
Now, don’t get too excited. You can’t use the full suite of syntax (which most people don’t know anyway). You can certainly accomplish a lot.
There’s one thing to remember: this is NOT RegEx. That’s important because RegEx is the fastest string parser in the universe. This only mimics the syntax. Don’t expect its performance. Having said that, I have tested it against LIKE wildcards (%) and it SMOKES them.
But check out what you can do:
Here are the results:
But it doesn’t seem to operate exactly how you would expect:
- As you can see [A-Z] works correctly, but [a-z] seemed broken.
- See how [ ] finds a space, but also an empty space (not expected).
(I am using SQL 2008 Developer Edition)