Google sheet formula to swap names - regex

I have this:
Image shows that those 2 cells contain input from another sheet.
Now, I want to input formula in those same cells that will rename inputs:
=if(D5="jerry.berry", "Berry Jerry", if(D5="perkins.aaron", "Aaron Perkins"))
Question: How do I insert the above formula next to =Source!H5
Note: I know I can modify those values on the root sheet itself, but I would rather not.

you can use regex like:
=ARRAYFORMULA(PROPER(REGEXREPLACE(Source!H5:H6, "(.+)\.(.+)", "$2 $1")))

I hope this is what you need:
Although I'd use a generic formula to manipulate (any) names in this string format.

Related

How can I extract specific patterns from a string?

I currently have a dataset filled with the following pattern:
My goal is to get each value into a different cell.
I have tried with the following formula, but it's not yielded the results I am looking for.
=SPLIT(D8,"[Stock]",FALSE,FALSE)
I would appreciate any guidance on how I can get to the ideal output, using Google Sheets.
Thank you in advance!
I will assume here from your post that your original data runs D8:D.
If you want to retain [Stock] in each entry, try the following in the Row-8 cell of a column that is otherwise empty from Row 8 downward:
=ArrayFormula(IF(D8:D="",,TRIM(SPLIT(REGEXREPLACE(D8:D&"~","(\[Stock\]).","$1~"),"~",1,1))))
If you don't want to retain [Stock] in each entry, use this version:
=ArrayFormula(IF(D8:D="",,TRIM(SPLIT(REGEXREPLACE(D8:D&"~","\[Stock\].","~"),"~",1,1))))
These formulas don't function based on using any punctuation at all as markers. They also assure that you don't wind up with blank (and therefore unusable) cells interspersed for ending SPLITs.
, only used in the separator
=ARRAYFORMULA(SPLIT(D8:D,", ",FALSE))
, used also in each string ([stock] will be replaced)
=ARRAYFORMULA(SPLIT(D8:D," [Stock], ",FALSE))
, used also in each string ([stock] will not be replaced)
=ArrayFormula(SPLIT(REGEXREPLACE(M9:M11,"(\[Stock\]), ","$1♦"),"♦"))
use:
=INDEX(TRIM(IFNA(SPLIT(D8:D; ","))))

Regexmatch for multiple words in Sheets

I'm trying to write a REGEXMATCH formula for Sheets that will analyze all of the text in a cell and then write a given keyword into another cell.
I've figured out how to do this for a single keyword: for example,
=IF(REGEXMATCH(F3, "czech"),"CZ",IF(REGEXMATCH(F3, "african"),"AF",IF(REGEXMATCH(F3, "mykonos"),"MK")))
What I'm having trouble with though is writing one of these values only if two or more terms are matched in the reference cell.
If I were trying to match one of two words, I realize I could use | as in:
=IF(REGEXMATCH(F3, "czech|coin"),"CZC"
etc
But in this instance I only want to produce CZC if the previous cell contains BOTH czech AND coin.
Can someone help me with this?
try like this:
=IF((REGEXMATCH(F3, "czech"))*(REGEXMATCH(F3, "coin")), "CZC", )
multiplication stands for AND

Google Sheets regexextract multiple text strings from a cell

I am trying to extract the hashtag info from a twitter data cell in google sheets.
We can call this Cell A1:
[{"text":"QOTD","indices":[13,18]},{"text":"CSEC4CG","indices":[87,95]},{"text":"myCSEC","indices":[96,103]},{"text":"Connecticut","indices":[104,116]},{"text":"GiveBack","indices":[117,126]},{"text":"COVID19","indices":[127,135]}]
In a perfect situation I would be able to produce this in another cell extracted from A1:
#QOTD #CSEC4CG #myCSEC #Connecticut #Giveback #COVID19
I am lost how to do it using REGEXTRACT. I assume this is the best method, but any that gets the job done is good.
Thank you for any help!
You want to achieve the following conversion using the built-in functions in Google Spreadsheet.
From
[{"text":"QOTD","indices":[13,18]},{"text":"CSEC4CG","indices":[87,95]},{"text":"myCSEC","indices":[96,103]},{"text":"Connecticut","indices":[104,116]},{"text":"GiveBack","indices":[117,126]},{"text":"COVID19","indices":[127,135]}]
To
#QOTD #CSEC4CG #myCSEC #Connecticut #Giveback #COVID19
If my understanding is correct, how about this answer?
Sample formula:
=TRIM(REGEXREPLACE(REGEXREPLACE(A1,"\[|\]|,",""),"{""text"":""(.+?)""""indices"":.+?}"," #$1"))
In this case, it supposes that the input value is put in the cell "A1".
The flow is as follows.
Replace \[|\]|, with "" using REGEXREPLACE.
Replace {""text"":""(.+?)""""indices"":.+?} with " #$1" using REGEXREPLACE.
The top space is removed with TRIM.
Result:
References:
REGEXREPLACE
TRIM

Avoid duplicate code in Excel IF formula code

I want to avoid duplicate code within excel formulas. Is there a method to repeat a certain code segment?
=IF(A1=1,(A1-B2-C3),(A1-B2-C3)+1)
This would be especially useful when it comes to more complex or longer sections. But: everything must be in ONE formula in ONE cell. Thanks! :-)
EDIT: This is my current code.
=IF(ISNUMBER(SEARCH(".amp",A2)),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-5),""),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-1),""))
It strips the long ID number out of any URL of a specific CMS. So
FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))
is probably the part which occurs more than once and should be replaced for a code which does not be that duplicate-prone.
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-123456789.html --> 1234567890
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-1234567890.amp.html ->
1234567890
EXAMPLE: www.domain.com/path1/this-is-an-article-1234567890.html ->
1234567890
In google sheets, you could use REGEXEXTRACT to get what you want:
Formula in B1:
=REGEXEXTRACT(A1,"\d{8,}")
Place the complex common sub-expression in its own cell and refer to that cell.
EDIT#1:
As an alternative, you can use a Named Formula for the sub-expression:
Named Formula
So here is another way of finding the code in Excel:
Here is the formula in Cell B1 which needs to be confirmed by pressing Ctrl+Shift+Enter, then drag it down to apply across board:
{=FILTERXML("<data><a>"&SUBSTITUTE(MID(A1,LARGE(IF(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1))),1)="-",ROW($A$1:INDEX($A:$A,LEN(A1)))),1)+1,LEN(A1)),".","</a><a>")&"</a></data>","/data/a[1]")}
For the logic behind this formula you may give a read to this article: Extract Words with FILTERXML.
Cheers :)
Ps. it seems that GoogleSheet has out performed Excel in some area already.

Conditional Vlook up without using VBA

I want to convert an input to desired output. Kindly help.
In the output - the columns value should start from most recent (year)
Please click this to see data
Unfortunately VLOOKUP is not able to fulfill that ask. However the INDEX-function can.
Here is a good read on how to use it:
http://fiveminutelessons.com/learn-microsoft-excel/use-index-lookup-multiple-values-list
This will work for you spreedsheet, if your input table starts at A1 without a header and your output table starts at H3 with the first ID.
You get this by copy&pasting the first column of your input table to column H and then remove duplicates.
{=IF(ISERROR(INDEX($A$1:$C$7,SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3)),"",
INDEX($A$1:$C$7;SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3))}
Let's look at the formula step by step:
The curly brackets tell excel that this is an array formula, the interesting part for you is: when you've inserted the formula (without curly brackets) press shift+ctrl+enter, excel will then know that this is an array formula.
'error at formula?, then blank, else formula
=IF(ISERROR(....),"",...)
When you autofill this formula you probably dont know how many instances of your lookup variable are. So when you put this formula in 4 cells, but there are only 3 entries, this bit will keep the cell blank instead of giving an error.
INDEX($A$1:$C$7,SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3))
$A$1:$C$7 is your data matrix. Your IDs (in your case 125 and 501) are to be found in $A$1:$A$7. ROW(1:1) is the absolute(!) rowID, 3 the absolute(!) column id. So when you move your input table those values have to be changed.
What exactly SMALL and INDEX do are well described in the link above. (Or at least better than I could.)
Hope that clarified some parts,
Tom