Microsoft Dev Blogs

Introducing Regular Expression (Regex) Support in Azure SQL DB

thumbnail

Table of Contents

  1. Introduction
  2. Feature Exploration
  3. Example Queries
  4. Feedback and Signup

Introducing Regular Expression (Regex) Support in Azure SQL DB

Azure SQL Database now offers a private preview of regular expressions (regex) support. This feature allows users to enhance SQL queries with pattern matching, extraction, replacement, and more. Regex support can be used to improve data quality, validate and correct data formats, extract valuable insights, and follow the POSIX standard.


Feature Exploration

REGEXP_LIKE

  • Function: Returns TRUE if a string matches a regular expression pattern.
  • Compatibility: Follows POSIX standard and supports standard regex syntax.

REGEXP_COUNT

  • Function: Returns the number of times a regular expression pattern matches in a string.
  • Usage: Useful for counting occurrences of specific patterns in text data.

REGEXP_INSTR

  • Function: Returns the position of a regular expression pattern in a string.
  • Transformation: Can be used to modify or transform text data based on regex patterns.

REGEXP_REPLACE

  • Function: Returns a substring that matches a regular expression pattern.
  • Purpose: Allows for replacing text based on regex patterns in a string.

REGEXP_SUBSTR

  • Function: Returns the substring that matches a regular expression pattern.
  • Extraction: Helpful for extracting specific parts of a string using regex patterns.

Example Queries

  1. Check Constraints Validation:

    • Validate email and phone_number columns in the Employees table.
  2. Filter Rows Based on Regex:

    • Query to filter rows where email domain ends with '.com'.
  3. REGEXP_COUNT Usage:

    • Query to count vowels in names from the Employees table.
  4. REGEXP_INSTR Demonstration:

    • Example showing phone number format transformation using REGEXP_INSTR.
  5. REGEXP_SUBSTR Demo:

    • Extracting phone number area codes using REGEXP_SUBSTR.

Feedback and Signup

If you are interested in trying out the regex feature in Azure SQL Database, please fill out the signup form. Your feedback is valuable as we continue to enhance SQL DB with regex support.