Google Sheets multiple search and replace from a list - list

I already found this solution, but unfortunately I can't comment or ask a question in this thread.
https://stackoverflow.com/a/47685929/19554304
Is there a way to change the script from the solution so that it is possible to check multiple words for a replacement. For example: Check if the text contains the words A or B and replace them with C.
Thx
Check if the text contains the words A or B and replace them with C.

You can solve it vía formula like this:
=reduce(C2,SEQUENCE(COUNTA(A:A)),LAMBDA(a,r,REGEXREPLACE(a,"\b("&INDEX(A:A,r)&")\b",INDEX(B:B,r,))))
You put the values separated by "|" in Column A and its replacements in column B. For example: "car|Moto"
Let me know if it is useful! You can use it as ARRAYFORMULA too by wrapping it in ARRAYFORMULA and changing C2 with the whole range of C column

Related

REGEX: Transpose each word from a google sheet cell and put them one under the other (rows)

I need to extract each word (phrase) within a cell in google sheets and put each one under the other in a column (row for each one).
I have a regex code that works when testing it, but I cannot do it work in google sheet the same code. Any ideas?
You can just do
=SUBSTITUTE(A1," ",char(10))
or
=transpose(split(A1," "))
You don't really need regex for this. You can use Transpose and split methods of google sheets.
Example:
In sheets in A1 put your text then in B1 copy this =TRANSPOSE(SPLIT(A1," "))
Update: this answer does not meet all requirements as it puts all results in one cell.
The ASCII character numbers need to be used instead of \r\n that you would expect from other tools.
Carriage return has number 13 and line feed has number 10:
=REGEXREPLACE(A1, "\s", CONCAT(CHAR(13), CHAR(10)))

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

How to put quotation marks around all parts of a Google Sheets formula that are not cell references

I want to be able to see my formulas with actual data in them to help with troubleshooting.
So I want to get a regular expression that will put quotation marks around all non-cell-reference items.
I tried
Original formula
=IFERROR(
(($Q10*24*Q$2)*($O10*$O$2)*( ($T10+$V10)*$S$2)*($P10*$P$2))/($R10*$R$2),"Spec missing")
Desired output
="IFERROR(
(("&$Q10&"*24*"&Q$2&")*("&$O10&"*"&$O$2&")*( ("&$T10&"+"&$V10&")*"&$S$2&")*("&$P10&"*"&$P$2&"))/("&$R10&"*"&$R$2&"),""Spec missing"")"
When I copy the output and paste as text, I want to get a formula in the cell that outputs text looks like this:
="IFERROR(
((0.363194444444444*24*1)*(17348*1)*( (4.096+18.874368)*1)*(2519*1))/(3*1),""Spec missing"")"
I can then copy that down and that helps me troubleshoot the formula (or the data) if something weird is happening.
Solution I found:
I copy the formula and paste it in F10 (with an ' in front of it so it comes up as a text string), then paste the following:
="="""&REGEXREPLACE(regexreplace(F2,"\""","\""\"""),"(\$?[A-Z]{1,2}\$?\d+)","""&$1&""")&""""
Description: i) The first regexreplace (going from innermost to outermost) I use to escape all the quotes in the formula by replacing all double quotes with two double quotes, so that quotes in the original formula won't mess things up. ii) The second REGEXREPplace finds things that match the "$A1" (or "A1" or "A$1") pattern, allowing up to two letters (eg. "AA1" will work as well). iii) I put "="""& before and &"""" and after to finish the formula.
One problem I still have with this setup is that it doesn't handle cell references in another worksheet, such as "Rankings!A1". I'm not sure what sort of regular expression I'd be able to use that could match everything before the "!" that could be part of a sheet name without starting to match other things . . .

Check if cell contains numbers in Google Spreadsheet using RegExMatch

I want to check if specific cell contain only numbers.
I know I should use RegExMatch but I get an error.
This is what I wrote : =if(RegExMatch(H2,[0-9]),"a","b")
I want it to say : write 'a' if H2 contains only numbers, 'b' otherwise.
Thank you
Try this:
=IF(ISNUMBER(H2,"A","B"))
or
=if(isna(REGEXEXTRACT(text(H2,"#"),"\d+")),"b","a")
One reason your match isn't working also - is that it in interpreting your numbers as text. the is number function is a bit more consistent, but if you really need to use regex, then you can see in the second formula where im making sure the that source text is matching against a string.
Your formula is right, simple you forget the double quotes at regexmatch function's regular_expression .
This is the right formula: =if(RegExMatch(B20,"[0-9]"),"a","b")
=REGEXREPLACE(“text”,”regex”,”replacement”)
It spits out the entire content but with the regular expression matched content replaced. =REGEXREPLACE(A2,[0-9],"a")
=REGEXREPLACE(A2,![0-9],"b")//not sure about not sign.
will fill a cell with the same text as A2, but with the 0-9 becoming an a!

Removing duplicate rows from Notepad++

I am looking for a way to remove duplicate rows from my Notepad++ file. The rows are not exact duplicates per say. Here's the situation. I have a large file of capitalized company names with probability values as well (each separated by a tab). So the format would be like this:
ATT .7213
SAMSUNG .01294
SAMSUNG .90222
So, I need to remove one of these rows because there is a match in the first column. I don't really have a preference of which one I need to remove just as long as I end up with one row at the end. I have tried to use unique sorting with TextFX but it's looking for the whole row duplicate and not just the first column. If anyone could offer up a handy solution to fix this I would greatly appreciate it. Bash script answers using awk, sed, or cut are also acceptable as well as using regular expressions.
Thank you!
Using awk, you could say:
awk '!a[$1]++' filename
This would keep only the lines having a unique value for the first field.
Use sort:
sort -k1,1 -u companies.txt
The output will consist of the full line, but only the sorting key (the first field) will be considered for identifying duplicates.