text_between
Extracts the text found between two delimiter substrings in a source string. Useful for parsing structured text where values are enclosed by known markers.
Syntax
text_between(source, before, after)
text_between(source, before, after, fallback)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| source | string | Yes | The source string to search within. |
| before | string | Yes | The opening delimiter. If None, extraction starts from the beginning of the string. |
| after | string | Yes | The closing delimiter. If None, extraction continues to the end of the string. |
| fallback | string | Optional | The value to return if either delimiter is not found. Defaults to None. |
Returns
Type: string
The substring found between the first occurrence of before and the first subsequent occurrence of after. Returns fallback if either delimiter is not found.
Examples
Extract a value between brackets:
text_between([raw_data], "[", "]")
If raw_data is "Status: [Active] - Priority: [High]", the result is "Active" (the first match).
Extract with a fallback value:
text_between([response], "error:", "\n", "No error found")
If response does not contain "error:", the result is "No error found".
Parse a value from XML-like text:
text_between([payload], "<id>", "</id>")
If payload is "<record><id>12345</id><name>Test</name></record>", the result is "12345".
Notes
- Only the first match is returned. If you need multiple matches, consider using
regex_replaceor XML/JSON path functions. - The search for
afterbegins from the position immediately following thebeforedelimiter. - Pass
Noneforbeforeto extract from the start, orNoneforafterto extract to the end.
Comments
0 comments
Please sign in to leave a comment.