REGEXP_REPLACE Function - SQL Server Documentation

Last Updated: 2023-10-26

Syntax

                
                    REGEXP_REPLACE (
                        expression, pattern, replacement, [position]
                    )
                
            

Description

The REGEXP_REPLACE function replaces occurrences of a regular expression pattern in a string with a specified replacement string.

This function is part of the SERVERPAST extension. You must enable the extension before using this function.

Learn more about Regular Expressions in SQL Server

Parameters

Example

                
                    SELECT REGEXP_REPLACE('My phone number is 123-456-7890', '[0-9]+', 'XXX', 1);
                    -- Result: My phone number is XXX-XXX-XXXX