Google Sheets – How to Drop Part of a Cell Value After a Specific Character

formulasgoogle sheetsregexextract

I have one cell that contains a long string of several values separated by "|".

EXAMPLE in Cell B5

title | time | location | cost

I need a formula that will show the value of B5, but only the characters before the first "|".

Is it possible to trim everything including and following a specific character?

Best Answer

=REGEXEXTRACT(B5, "[^\s|]+")

0

  • \s a space
  • \s| a space followed by | character
  • ^ the first
  • ^\s| the first match of a space followed by | character
  • [] a group
  • [^\s|] a group found before the first match of a space followed by | character
  • + more than one character if possible
  • [^\s|]+ extract a group of characters before the first occurrence of a space followed by | character