REGEXREPLACE - Query language in Cosmos DB (in Azure and Fabric)

The REGEXREPLACE function returns a string where the first regular expression match is replaced.

An Azure Cosmos DB system function that performs a regular expression replacement for the first match.

Syntax

REGEXREPLACE(<subject>, <pattern>, <replacement>, [<options>])

Arguments

Description
subject The string to search.
pattern The regular expression pattern to match.
replacement The string that replaces the first match.
options Optional. A string of regular expression flags: i (ignore case), m (multiline), s (singleline or dotall), and x (ignore pattern whitespace).

Return types

Returns a string expression.

Examples

This section contains examples of how to use this query language construct.

Replace the first regular expression match

In this example, the REGEXREPLACE function replaces only the first numeric sequence.

SELECT VALUE {
  replaceFirst: REGEXREPLACE("A12-B34-C56", "[0-9]+", "#")
}
[
  {
    "replaceFirst": "A#-B34-C56"
  }
]

Remarks

  • This function doesn't use the index.