I am wondering, is it possible to translate regex containing '?' (preceding item optional) in T-SQL LIKE pattern? Without any actions on the DB side. For example, "^31-?4"
. I could split it up into several clauses, but if regex contains a lot of '?' this is not that convenient.
We use regular expressions to define specific patterns in T-SQL in a LIKE operator and filter results based on specific conditions. We also call these regular expressions as T-SQL RegEx functions. In this article, we will use the term T-SQL RegEx functions for regular expressions.
Regular expressions are a concise and flexible notation for finding and replacing patterns of text. A specific set of regular expressions can be used in the Find what field of the SQL Server Management Studio Find and Replace dialog box.
SQL Pattern Matching : It is used for searching a string or a sub-string to find certain character or group of characters from a string. We can use LIKE Operator of SQL to search sub-string. The LIKE operator is used with the WHERE Clause to search a pattern in string of column.
LIKE
doesn't use regular expressions and the pattern language it uses doesn't have tokens and qualifiers, just a few placeholders:
Wildcard character Description
------------------ -----------
% Any string of zero or more characters.
_ (underscore) Any single character.
[ ] Any single character within the specified range ([a-f]) or set ([abcdef]).
[^ ] Any single character not within the specified range ([^a-f]) or set ([^abcdef]).
So no, there isn't such a thing you ask for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With