Text.BetweenDelimiters
The part of a text between a start delimiter and the end delimiter that follows it.
Group: Text and characters. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Text.BetweenDelimiters(text as nullable text, startDelimiter as text, endDelimiter as text, optional startIndex as any, optional endIndex as any) as any
| Parameter | Type | Description |
|---|---|---|
text | nullable text | The text to work on; null gives null. |
startDelimiter | text | The text that opens the part you want. |
endDelimiter | text | The text that closes it. |
startIndex | any optional | Which start delimiter to use, from 0; or {index, RelativePosition.FromEnd}. Left out, the first. |
endIndex | any optional | Which end delimiter after the start one to use, from 0; or {index, RelativePosition.FromEnd}. Left out, the first. |
Returns
any. The text between the two delimiters; empty when the start delimiter isn't there.
Remarks
- The end delimiter is looked for only after the start delimiter, so the same character may open and close the part (quotes, for example).
Examples
An order code in brackets
Text.BetweenDelimiters("Order [A-1001] shipped", "[", "]")
"A-1001"
The second pair of parentheses
Text.BetweenDelimiters("Chair (oak) and desk (pine)", "(", ")", 1, 0)
"pine"
Start index 1 is the second opening parenthesis; end index 0 the first closing one after it.