2

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?

| | | | | |
  • See answer below - that should do the trick – Aurielle Perlmann Oct 2 '16 at 3:36
1

=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
    if ^ is "the first", what would give the second or third? – Trey Sep 11 '19 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

| | | | | |
  • 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 Sep 30 '16 at 21:17
  • =TRIM(INDEX(split(B5, "|"),1)) – Max Makhrov Oct 3 '16 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, privacy policy and cookie policy

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