Last active
January 28, 2026 17:22
-
-
Save Medohh2120/ac4638ecdacd791fb33c6f745dbd3342 to your computer and use it in GitHub Desktop.
Returns text between 2 delimiters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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) | |
| ) | |
| ); |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Example: