Google Sheets Trim after either of characters - regex

I have a column of cells in Google Sheets with text in the following formats:
PLAYBILL59; Code Description Here
BROADWAYBOX59: Code Description Here
TICKETCODE: Code Description Here
I want to create a formula that deletes everything after and including either a colon or semi-colon, that would leave:
PLAYBILL59
BROADWAYBOX59
TICKETCODE
I've been trying for hours with no luck.
Any suggestions very appreciated.

Let's say that your colum is A, then you can use REGEXEXTRACT in your formula like
=REGEXEXTRACT(A1; "[A-Z0-9-a-z]+")

Assuming your text string is in A1, try:
=SUBSTITUTE(SUBSTITUTE(A1, "; Code Description Here",""), ": Code Description Here", "")

Related

Removing the last specific character from the results of my formula

I'm using some VLOOKUPs to pull in text from another tab on my spreadsheet using the below formula
={"Product Category Test";ARRAYFORMULA(IF(ISBLANK(A2:A),"",
VLOOKUP(A2:A,'Import Template'!A:DB,MATCH("Product Category",'Import
Template'!A1:DB1,0),false)&"|"&IF(VLOOKUP(A2:A,'Import Template'!A:DB,MATCH("Automatic
Categories",'Import Template'!A1:DB1,0),false)<>"",VLOOKUP(A2:A,'Import
Template'!A:DB,MATCH("Automatic Categories",'Import Template'!A1:DB1,0),false),"")))}
Example of results: Books|Coming Soon Images|
All of my results will be delimited by a "|" which will also be the final character. I need to remove the final "|" from the results ideally without using a helper column, is there a way to wrap another function around my formula to achieve this? I've played around with RIGHT and LEN but can't figure it out.
Thanks,
use regex:
=ARRAYFORMULA({"Product Category Test"; REGEXREPLACE(""&IF(ISBLANK(A2:A),,
VLOOKUP(A2:A,'Import Template'!A:DB,MATCH("Product Category",'Import
Template'!A1:DB1,0),)&"|"&IF(VLOOKUP(A2:A,'Import Template'!A:DB,MATCH("Automatic
Categories",'Import Template'!A1:DB1,0), )<>"",VLOOKUP(A2:A,'Import
Template'!A:DB,MATCH("Automatic Categories",'Import Template'!A1:DB1,0),),)), "\|$", )})
if this won't work make sure there are no empty spaces after last |

Extract a list of unique text characters/ emojis from a cell

I have a text in cell (A1) like this:
✌😋👅👅☝️😉🍌🍪💧💧
I want to extract the unique emojis from this cell into separate cells:
✌😋👅☝️😉🍌🍪💧
Is this possible?
You want to put each character of ✌😋👅👅☝️😉🍌🍪💧💧 to each cell by splitting using the built-in function of Google Spreadsheet.
Sample formula:
=SPLIT(REGEXREPLACE(A1,"(.)","$1#"),"#")
✌😋👅👅☝️😉🍌🍪💧💧 is put in a cell "A1".
Using REGEXREPLACE, # is put to between each character like ✌#😋#👅#👅#☝#️#😉#🍌#🍪#💧#💧#.
Using SPLIT, the value is splitted with #.
Result:
Note:
In your question, the value of ️ which cannot be displayed is included. It's \ufe0f. So "G1" can be seen like no value. But the value is existing. So please be careful this. If you want to remove the value, you can use ✌😋👅👅☝😉🍌🍪💧💧.
References:
REGEXREPLACE
SPLIT
Added:
From marikamitsos's comment, I could notice that my understanding was not correct. So the final result is as follows. This is from marikamitsos.
=TRANSPOSE(UNIQUE(TRANSPOSE(SPLIT(REGEXREPLACE(A1,"(.)","$1#"),"#"))))
or try:
=TRANSPOSE(UNIQUE(TRANSPOSE(REGEXEXTRACT(A1, REPT("(.)", LEN(A1))))))
Formula
Appears, one of the best formula solutions would be:
=SPLIT(REGEXREPLACE(A1,"(.)","$1#"),"#")
You may also add some additional checks like skin tones & intermediate chars:
=TRANSPOSE(SPLIT(REGEXREPLACE(A2,"(.[🏻🏼🏽🏾🏿"&CHAR(8205)&CHAR(65039)&"]*)","#$1"),"#"))
It will help to join some emojis as a single emoji.
Script
More precise way is to use the script:
https://github.com/orling/grapheme-splitter/blob/master/index.js
↑
Add the code to Script editor
Add code for sample usage:
function splitEmojis(string) {
var splitter = new GraphemeSplitter();
// split the string to an array of grapheme clusters (one string each)
var graphemes = splitter.splitGraphemes(string);
return graphemes;
}
Tests
Not 100% precise
1
Please note: some emojis are not correctly shown in sheets
🏴󠁧󠁢󠁷󠁬󠁳󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁥󠁮󠁧󠁿🏴
↑ emojis:
flag: England
flag: Scotland
flag: Wales
black flag
are the same for Google Sheets.
2
Vlookup function in #GoogleSheets and in #Excel thinks chars
#️⃣ and
*️⃣
are the same!

How to reshape timestamp in Google Sheets?

I have an imported cell in Google Sheets with the following string representing a time/date format:
2019-03-30T14:39:07-03:00
What would be the correct REGEXTRACT or DATEVALUE formula solution so that it will result in a valid Google Sheets date&time format?
The -03:00 at the end of the string can be ignored.
2019-03-30T14:39:07-03:00
should result in
yyyy-mm-dd hh:mm:ss
You can use REGEXREPLACE and use this regex,
.*?(\d{4}(?:-\d{2}){2}).(\d{2}(?::\d{2}){2}).*
And replace it with $1 $2.
Demo
I've tested and it works well in Google sheets.
Just use this,
=REGEXREPLACE(A1, ".*?(\d{4}(?:-\d{2}){2}).(\d{2}(?::\d{2}){2}).*", "$1 $2")
And replace in the cell you want to get your desired value.
Here is a screenshot showing the google sheets demo,
As you can see in the samples, this regex will find the date, no matter the date is surrounded by any optional text. In each of the case, you will have your desired date extract in the next column or any column you want.
all you need is:
=SUBSTITUTE(LEFT(A1, 19), "T", " ")
for the whole column:
=ARRAYFORMULA(SUBSTITUTE(LEFT(A1:A, 19), "T", " "))

Excel formula has too many arguments

I created the below formula to run of a series of customer numbers saved in text format.
=IFERROR(IF(AND((LEFT($J3,3)="028"),$N3=11),"NI Landline",IF(AND((LEFT($J3,2)="07"),$N3=11),"Mobile","Other Number")),"Other Number")
Breakdown:
=IFERROR(
IF(AND((LEFT($J3,3)="028"),$N3=11),
"NI Landline",
IF(AND((LEFT($J3,2)="07"),$N3=11),
"Mobile",
"Other Number")),
"Other Number")
This formula works fine but I needed to amend it slightly to differentiate the numbers a bit further, so I amended it to the below:
=IFERROR(IF(AND((LEFT($J2,3)="028"),$N2=11),"NI Landline",IF(AND((LEFT($J2,2)="07"),$N2=11),"UK Mobile",IF(AND((LEFT($J2,5)="00353"),$N2=14),"ROI Number","Other Number")),"Other Number")
Breakdown:
=IFERROR(
IF(AND((LEFT($J2,3)="028"),$N2=11),
"NI Landline",
IF(AND((LEFT($J2,2)="07"),$N2=11),
"UK Mobile",
IF(AND((LEFT($J2,5)="00353"),$N2=14),
"ROI Number",
"Other Number")),
="Other Number")
Thinking I've replicated the conditions from the first 'IF' sections, I ran the formula and it returned 'too many arguments'. I've removed the new section so that it is the same as the first formula, and it works fine. I've checked the parentheses but the number matches on both sides. Any ideas?
I'm hoping it is something stupid, any assistance would be greatly appreciated!
Thanks
Liam
you seem to be closing the brackets early for the and() statements : try removing the close brackets after 028" and 07" and 353"
So did a bit for the first two as per :
IF(AND(LEFT($J2,3)="028",$N2=11),"NI Landline",IF(AND((LEFT($J2,2)="07"),$N2=11),"UK Mobile","check"))
You should be able to expand from here.
Image to show the example :
"too many arguments" means the number of "," , , "(" & ")" is not right. Just double check for each if(a,b,c) iferror(a,b), and and(a,b,c) to have enough brackets, data/arguments and comma. That should be sufficient.
Note: #Solar Mike had shared a great solution though. (:

How can I separate a string by underscore (_) in google spreadsheets using regex?

I need to create some columns from a cell that contains text separated by "_".
The input would be:
campaign1_attribute1_whatever_yes_123421
And the output has to be in different columns (one per field), with no "_" and excluding the final number, as it follows:
campaign1 attribute1 whatever yes
It must be done using a regex formula!
help!
Thanks in advance (and sorry for my english)
=REGEXEXTRACT("campaign1_attribute1_whatever_yes_123421","(("&REGEXREPLACE("campaign1_attribute1_whatever_yes_123421","((_)|(\d+$))",")$1(")&"))")
What this does is replace all the _ with parenthesis to create capture groups, while also excluding the digit string at the end, then surround the whole string with parenthesis.
We then use regex extract to actuall pull the pieces out, the groups automatically push them to their own cells/columns
To solve this you can use the SPLIT and REGEXREPLACE functions
Solution:
Text - A1 = "campaign1_attribute1_whatever_yes_123421"
Formula - A3 = =SPLIT(REGEXREPLACE(A1,"_+\d*$",""), "_", TRUE)
Explanation:
In cell A3 We use SPLIT(text, delimiter, [split_by_each]), the text in this case is formatted with regex =REGEXREPLACE(A1,"_+\d$","")* to remove 123421, witch will give you a column for each word delimited by ""
A1 = "campaign1_attribute1_whatever_yes_123421"
A2 = "=REGEXREPLACE(A1,"_+\d*$","")" //This gives you : *campaign1_attribute1_whatever_yes*
A3 = SPLIT(A2, "_", TRUE) //This gives you: campaign1 attribute1 whatever yes, each in a separate column.
I finally figured it out yesterday in stackoverflow (spanish): https://es.stackoverflow.com/questions/55362/c%C3%B3mo-separo-texto-por-guiones-bajos-de-una-celda-en...
It was simple enough after all...
The reason I asked to be only in regex and for google sheets was because I need to use it in Google data studio (same regex functions than spreadsheets)
To get each column just use this regex extract function:
1st column: REGEXP_EXTRACT(Campaña, '^(?:[^_]*_){0}([^_]*)_')
2nd column: REGEXP_EXTRACT(Campaña, '^(?:[^_]*_){1}([^_]*)_')
3rd column: REGEXP_EXTRACT(Campaña, '^(?:[^_]*_){2}([^_]*)_')
etc...
The only thing that has to be changed in the formula to switch columns is the numer inside {}, (column number - 1).
If you do not have the final number, just don't put the last "_".
Lastly, remember to do all the calculated fields again, because (for example) it gets an error with CPC, CTR and other Adwords metrics that are calculated automatically.
Hope it helps!