Excel BI - Excel Challenge 729

excel-challenges
excel-formulas
πŸ”° Extract texts between delimiter ~ (tilde) only if it is a single word.
Published

March 24, 2026

Illustration for Excel BI - Excel Challenge 729

Challenge Description

πŸ”° Extract texts between delimiter ~ (tilde) only if it is a single word. Hence, if text extracted is β€˜hail Mary’, then this should not be extracted as this is not a single word.

Solutions

library(tidyverse)
library(readxl)

path = "Excel/700-799/729/729 Extract Text Between Delimiters.xlsx"
input = read_excel(path, range = "A1:A10")
test = read_excel(path, range = "B1:B10") %>%
  replace_na(list(`Answer Expected` = ""))

result = input %>%
  rowwise() %>%
  mutate(
    `Answer Expected` = list(str_match_all(Text, "(?<=~)\\w+(?=~)")[[1]]) %>%
      unlist() %>%
      paste(collapse = ", ")
  )

all.equal(result$`Answer Expected`, test$`Answer Expected`)
#> TRUE
  • Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns.
  • Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
  • Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
  • Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import pandas as pd
import re

path = "700-799/729/729 Extract Text Between Delimiters.xlsx"
input_df = pd.read_excel(path, usecols="A", nrows=10)
test_df = pd.read_excel(path, usecols="B", nrows=10).fillna({"Answer Expected": ""})

input_df["Answer Expected"] = input_df.iloc[:,0].astype(str).apply(lambda x: ", ".join(re.findall(r"(?<=~)\w+(?=~)", x)))

print(input_df["Answer Expected"].equals(test_df["Answer Expected"]))
# True

The Python version expresses the core extraction rule directly and keeps the pattern matching easy to review.

Difficulty Level

Easy / Medium

The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.