Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract substring after '-' character in Google Sheets

I am using the following formula to extract the substring venue01 from column C, the problem is that when value string in column C is shorter it only extracts the value 1 I need it to extract anything straight after the - (dash) no matter the length of the value text in column c

={"VenueID";ARRAYFORMULA(IF(ISBLANK(A2:A),"",RIGHT(C2:C,SEARCH("-",C2:C)-21)))}

enter image description here

like image 924
Roggie Avatar asked Jun 11 '20 06:06

Roggie


People also ask

How do you remove the text before or after a specific character in Google Sheets?

RIGHT+LEN+FIND. There are a few more Google Sheets functions that let you remove the text before a certain character. They are RIGHT, LEN and FIND.

How do I extract specific text from Google Sheets?

Extract data before a certain text — LEFT+SEARCH Whenever you want to extract data that precedes a certain text, use LEFT + SEARCH: LEFT is used to return a certain number of characters from the beginning of cells (from their left) SEARCH looks for certain characters/strings and gets their position.


2 Answers

There is a much simpler solution using regular expressions.

=REGEXEXTRACT(A1,".*-(.*)")

In case you are no familiar with Regular Expressions what this means is, get me every string of characters ((.*)) after a dash (-).

Example

Sample of RegExtract

Reference

  • REGEXTRACT
  • Test regular expressions
  • Cheat sheet for regular expressions
like image 58
Raserhin Avatar answered Oct 23 '22 22:10

Raserhin


To answer bomberjackets question in the comment of Raserhin:

To select the part of the string before the "-"

=REGEXEXTRACT(A1,"(.*)-.*")

EXAMPLE

example of code

like image 32
Rousseau Nutter Avatar answered Oct 23 '22 22:10

Rousseau Nutter