23

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.

Qué Padre
  • 2,005
  • 3
  • 24
  • 39
  • Since this question is really old check https://stackoverflow.com/questions/194652/sql-server-regular-expressions-in-t-sql Oracle databases now support regex – devssh Aug 29 '18 at 06:11

1 Answers1

26

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.

Joey
  • 344,408
  • 85
  • 689
  • 683