Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

Support POSIX-style regular expressions in T-SQL

Regular expressions is a very powerful way to match data, far more powerful
than the LIKE operator in SQL. Regular expressions comes in a number of flavours:
POSIX defines one standard, .Net have their own twist (I think), and Perl is
probably the most elaborate of them all. But they all share some common
traits: . is a wildchard charcted, * means previous pattern zero or more times etc.

ANSI/ISO have tried to catch up, and SQL:1999 introduced the SIMILAR TO
operator, but it's obvious that they are on the wrong track. They still use % and
_ as wildcard which is simply akward and non-standard. They also insist on
the string matching the pattern entirely which also is non-standard.

Today you can use regpexps through the CLR routines, but this is common
enough to warrant a place directly in T-SQL. Also, that makes it difficult
to use indexes with regexps when you do an anchored search.

2 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    AdminMicrosoft SQL Server (Admin, Microsoft Azure) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    unplanned  ·  AdminMicrosoft SQL Server (Admin, Microsoft Azure) responded  · 

    Upvotes: 22

    <=-=Aug 12 2008 2:12PM=-=>

    Of course, there should also a be a replace function that can work with regular expression. Both for the pattern to find – and for the replacement string.

    <=-=Aug 13 2008 7:16AM=-=>

    Hi Erland,

    I’ve resolved this as a duplicate of Connect #261342 and made sure your comments are reflected in that issue. I can tell you that this is under serious consideration right now. If you haven’t already voted on that item, it would be worth it to do so.

    Thanks,
    -Isaac

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base