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?

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

Answer accepted by question author
  1. Viorel 125.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 128.7K Reputation points MVP Volunteer Moderator
    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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.