Skip to content

Instantly share code, notes, and snippets.

@Medohh2120
Last active January 28, 2026 17:22
Show Gist options
  • Select an option

  • Save Medohh2120/ac4638ecdacd791fb33c6f745dbd3342 to your computer and use it in GitHub Desktop.

Select an option

Save Medohh2120/ac4638ecdacd791fb33c6f745dbd3342 to your computer and use it in GitHub Desktop.
Returns text between 2 delimiters
/*
Name: TEXTBETWEEN
Description: Returns text between delimiters.
- Standardized to native TEXTAFTER/BEFORE syntax.
- Supports Multi-input: Text (Rows) x Delimiters (Columns).
- Strict Mode: Assumes equal number of start/end delimiters.
Made By: Medohh2120
*/
TEXTBETWEEN = LAMBDA(text, start_delim, end_delim, [instance_start], [instance_end], [case_sensitive_start], [case_sensitive_end], [match_end_start], [match_end_end], [if_not_found],
LET(
/* 1. Flatten inputs for safe indexing */
F_start_delim, TOCOL(start_delim),
F_end_delim, TOCOL(end_delim),
F_text, TOCOL(text),
/* 3. Early exit for single delimiter */
Normal_Case, COUNTA(start_delim) = 1,
IF(Normal_Case,
TEXTBETWEEN_Simple(text, start_delim, end_delim, instance_start, instance_end, case_sensitive_start, case_sensitive_end, match_end_start, match_end_end, if_not_found),
DROP(
REDUCE("", SEQUENCE(ROWS(F_start_delim)), LAMBDA(acc, nxt,
LET(
/*current pair of delimiters */
curr_start, INDEX(F_start_delim, nxt),
curr_end, INDEX(F_end_delim, nxt),
step1, TEXTAFTER(F_text, curr_start, instance_start, case_sensitive_start, match_end_start, if_not_found),
result_col, TEXTBEFORE(step1, curr_end, instance_end, case_sensitive_end, match_end_end, if_not_found),
/* Stack results */
HSTACK(acc, result_col)
)
)),,1
)
)
)
);
TEXTBETWEEN_Simple = LAMBDA(txt,start_delim,end_delim,
[instance_start],
[instance_end],
[case_sensitive_start],
[case_sensitive_end],
[match_end_start],
[match_end_end],
[if_not_found],
LET(
step1, TEXTAFTER(txt, start_delim, instance_start, case_sensitive_start, match_end_start, if_not_found),
TEXTBEFORE(step1, end_delim, instance_end, case_sensitive_end, match_end_end, if_not_found)
)
);
@Medohh2120
Copy link
Author

Medohh2120 commented Jan 26, 2026

Example:

image

@Medohh2120
Copy link
Author

Medohh2120 commented Jan 28, 2026

Ignore the following If you input text as a single column:

If you input multiple Text columns with single delimiters, shape is preserved.
image

If you input multiple Text columns AND multiple Delimiters, the input size isn't preserved and automatically flattened vertically to preserve integrity.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment