Is there analogue of C# "\d*" in t-sql?

Decompressor 81 Reputation points
2021-02-20T15:36:40.757+00:00

Is there analogue of C# "\d*" in t-sql?

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,575 questions
{count} votes

Accepted answer
  1. Viorel 113.7K Reputation points
    2021-02-20T16:19:23.173+00:00

    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).

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 103.2K Reputation points MVP
    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.

    0 comments No comments