4

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?

1
  • See answer below - that should do the trick Commented Oct 2, 2016 at 3:36

5 Answers 5

4

=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
1
  • 1
    if ^ is "the first", what would give the second or third?
    – TC76
    Commented Sep 11, 2019 at 0:07
4

Split formula may fit your needs:

=split(B5, "|")

next step: use index to return any of splitted words:

=TRIM(INDEX(split(B5, "|"),1))

change 1 to your number, this is the index of a word to return

2
  • thanks for the input, but that isn't what I'm looking for. I don't want to keep the data remaining after the "|" and place it in other cells. I just want it to 'go away'. Any other ideas?
    – Mr. B
    Commented Sep 30, 2016 at 21:17
  • =TRIM(INDEX(split(B5, "|"),1)) Commented Oct 3, 2016 at 6:07
2

You can just wrap it with trim

=Trim (split (B5,"|"))
1

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

=TRIM(LEFT(B5,SEARCH("|",B5)-1)

The result is title

1

You can try =LEFT(B5,SEARCH("|",B5)-1).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.