This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge

Get a match for a regular expression from a source string.

Optionally, convert the extracted substring to the indicated type.

Syntax

extract( regex , captureGroup , source [ , typeLiteral ] )

Learn more about syntax conventions .

Parameters

Required Description The capture group to extract. 0 stands for the entire match, 1 for the value matched by the first '('parenthesis')' in the regular expression, and 2 or more for subsequent parentheses. source string The string to search. typeLiteral string If provided, the extracted substring is converted to this type. For example, typeof(long) .

Returns

If regex finds a match in source : the substring matched against the indicated capture group captureGroup , optionally converted to typeLiteral .

If there's no match, or the type conversion fails: null .

Examples

The example string Trace is searched for a definition for Duration . The match is converted to real , then multiplied it by a time constant ( 1s ) so that Duration is of type timespan . In this example, it's equal to 123.45 seconds:

| extend Trace="A=1, B=2, Duration=123.45, ..." | extend Duration = extract("Duration=([0-9.]+)", 1, Trace, typeof(real)) * time(1s)

This example is equivalent to substring(Text, 2, 4) :

extract("^.{2,2}(.{4,4})", 1, Text)
			Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback.		

Submit and view feedback for

This product