I think that patterns are currently much limited in SQL. Sometimes you can write several patterns such as “…[0-9]…”, “…[0-9][0-9]…”, etc. or consider other solutions. Or extract the data and continue processing on client side, in C#. It is also possible to invoke your C# code from SQL (See CREATE ASSEMBLY and CREATE FUNCTION).
Is there analogue of C# "\d*" in t-sql?
Decompressor
81
Reputation points
Is there analogue of C# "\d*" in t-sql?
Accepted answer
1 additional answer
Sort by: Most helpful
-
Erland Sommarskog 107.2K Reputation points
2021-02-20T17:22:30.51+00:00 \d+ is not a C# feature per se, but regular expressions are supported in many environments, but alas not in T-SQL which offers a very meagre support for pattern matching.
As Viorel says, you can still use regular expression in SQL Server by using a CLR stored procedure or a function.
However, there is a bit of red tape of using the CLR, at least if you only have an occasional assembly. Another option, available since SQL 2017, is to run a Python script through sp_execute_external_sp. This is somewhat less complicated.