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

The REGEXEXTRACTALL function returns an array of substrings that match a regular expression pattern.

An Azure Cosmos DB system function that extracts all matches for a regular expression.

Syntax

REGEXEXTRACTALL(<subject>, <pattern>, [<options>], [<group_number>])

Arguments

Description
subject The string to search.
pattern The regular expression pattern to match.
options Optional. A string of regular expression flags: i (ignore case), m (multiline), s (singleline or dotall), and x (ignore pattern whitespace).
group_number Optional. The 1-based index of the capture group to return for each match. A value of 0, or omitting this argument, returns the full matches.

Return types

Returns an array expression.

Examples

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

Extract all matches with a regular expression

In this example, the REGEXEXTRACTALL function returns all numeric matches from the input string.

SELECT VALUE {
  allDigits: REGEXEXTRACTALL("A12-B34-C56", "[0-9]+"),
  allWords: REGEXEXTRACTALL("north-east-west", "[a-z]+")
}
[
  {
    "allDigits": ["12", "34", "56"],
    "allWords": ["north", "east", "west"]
  }
]

Extract a capture group from all matches

In this example, the REGEXEXTRACTALL function returns the captured numeric portion for each SKU match.

SELECT VALUE {
  skuNumbers: REGEXEXTRACTALL("sku-93821-blue sku-48152-red", "sku-([0-9]+)-[a-z]+", "i", 1)
}
[
  {
    "skuNumbers": ["93821", "48152"]
  }
]

Remarks

  • This function doesn't use the index.