Counting words in ARRAYS with ARRAYFORMULA in Google Sheets - regex

Counting words with Array formula for every cell won't work.
I have tried to use:
=ARRAYFORMULA(COUNTA(SPLIT(Range, " ")))
=ARRAYFORMULA(SUM(COUNTA(SPLIT(Range," "))))
Both didn't work.
I expected ARRAYFORMULA to count words for every cell in the column and put it next to it, but it counted all the text and put it in one cell instead.
Copy of the sheet (Problem in Cell D123): https://docs.google.com/spreadsheets/d/1pPbJ9k4tiLk8hVxHXRgvu6b4vxJOcgTmyFhD_g8gc_Q/edit?usp=sharing

=ARRAYFORMULA(IF(LEN(A3:A),
MMULT(IF(IFERROR(SPLIT(IF(LEN(A3:A), A3:A, ), " "))<>"", 1, 0),
ROW(INDIRECT("A1:A"&COUNTA(IFERROR(
QUERY(IF(IFERROR(SPLIT(IF(LEN(A3:A), A3:A, ), " "))<>"", 1, 0), "limit 1", 0)))))^0), ))
also could be done by just counting the spaces:
=ARRAYFORMULA(IF(LEN(A3:A), LEN(REGEXREPLACE(A3:A, "[^\s]", ))+1, ))

Related

Google Sheet Array Formula Put blank

I have this formula
=ArrayFormula(IF(LEN(C$3:F$3), H4:L4+C4:F4/$C$1, ""))
How i can modify this array formula to return Blank like in I7?
try:
=BYROW(B34:F38, LAMBDA(x, INDEX(SPLIT(TEXTJOIN(" ", 1, x), " "),,1)))

Having a problem with IF function argument in Spreadsheet

I'm trying to make this description generator, and I can't seem to make the first part work for one of the IF arguments as it does with the rest. It only checks the logical expression but doesn't bring the rest of the text body in the cell joined with & as it does in the case of the other IF arguments I have there linked one after the other. This example should make more sense.
try:
=INDEX(REGEXREPLACE(SUBSTITUTE(SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(IFERROR(
SPLIT(B1:B, CHAR(10)))="",,REGEXREPLACE({"", SEQUENCE(1, 100)}&". "&IFNA(VLOOKUP(
TRIM(SPLIT(B1:B, CHAR(10))),
{"ck", "click >";
"box", "select box";
"scd", "scroll down >"}, 2, 0),
SPLIT(B1:B, CHAR(10))), " ", CHAR(13)))),,9^9))),
" ", CHAR(10)), CHAR(13), " "), "^\. !?", ))
demo sheet
The first If statement encloses all the rest of the formula so if the regex matches "ck" the condition is satisfied, you get "click >" but nothing else happens. I think you can just move the final bracket so it is just after "select " like this:
=IF(REGEXMATCH(B4, "ck"),"click >",IF(REGEXMATCH(B4, "scd"),"scroll down > ",IF(REGEXMATCH(B4, "!"),"","select "))) & ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(TEXTJOIN(CHAR(10), 1, IF(REGEXMATCH(""&
SPLIT(B4, CHAR(10)), "^>.*"),
SPLIT(B4, CHAR(10)), TRANSPOSE(MMULT(TRANSPOSE(TRANSPOSE((SEQUENCE(1, COLUMNS(
SPLIT(B4, CHAR(10))))<=SEQUENCE(COLUMNS(
SPLIT(B4, CHAR(10))), 1, 0))*NOT(REGEXMATCH(
SPLIT(B4, CHAR(10)), "^>.+")))), TRANSPOSE(SIGN(NOT(REGEXMATCH(
SPLIT(B4, CHAR(10)), "^>.+"))))))&". "&
SPLIT(B4, CHAR(10)))), "^0. ", ),"scd",""),"ck",""),"!",""))

Reference text from cell and return remaining text to other cell

So my question is... I have 2 columns, A and B. In B I want to read the text from A (which has a list of texts: eg. Normal Car, Lorry, Sports Car, Bike) and I would type some text specified from the list in 'A' (eg. Bike) and in B would be the text that is left from that list from 'A' (So meaning "Normal Car", "Lorry" and "Sports Car" would be shown in 'B')
How do I do that?
This is the spreadsheet example:
https://docs.google.com/spreadsheets/d/16o75-R-U3zY0vajg1pO0N7-t9uGCtt_B2QiZLW_sXUM/edit#gid=0
Here are all the words that will be used: Lyrics, Visualizer, Bass Boost, 8D, Nightcore, Image Only
What I want to achieve is if I fill one or more of the words in Column A, then all the rest of the words will be filled up in B automatically. I left them filled up already so you can see the example. Thanks.
for one word:
=ARRAYFORMULA(REGEXREPLACE(TRIM(IF(LEN(A1:A),
REGEXREPLACE("Lyrics, Visualizer, Bass Boost, 8D, Nightcore, Image Only,",
A1:A&",", ), )), ",$", ))
for multiple words:
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A1:A), SUBSTITUTE(
REGEXREPLACE({"Lyrics", "Visualizer", "Bass Boost", "8D", "Nightcore", "Image Only"},
REGEXREPLACE(A1:A, ", ", "|"), ), " ", "♦"), )),,999^99))), " ", ", "), "♦", " "))
I would type some text specified from the list in 'A' (eg. Bike) and in B would be the text that is left from that list from
try like this:
=ARRAYFORMULA(REGEXREPLACE(TRIM(REGEXEXTRACT(A1:A, "(.*)"&B1:B)), ",$", ))

How to change a text or symbol into line break in Google Sheets?

I'm trying to change all ; into a line break \n in Google Sheets.
Is there a way to automate this or I need to do it one by one?
use SUBSTITUTE or REGEXREPLACE formulas wrapped in the ARRAYFORMULA like:
=ARRAYFORMULA(SUBSTITUTE(your_formula_or_range_here, ";", CHAR(10))
=ARRAYFORMULA(REGEXREPLACE(your_formula_or_range_here, ";", CHAR(10))
example:
=ARRAYFORMULA(SUBSTITUTE(QUERY({INDEX(QUERY(A1:B,
"select A,count(A) where A is not null group by A pivot B", 0), , 1),
REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(QUERY(A1:B,
"select count(A) where A is not null group by A pivot B", 0)), INDEX(QUERY({A1:A,B1:B&";"},
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 offset 1", 0), 1,), ))
, , 999^99))), ";$", )}, "offset 1", 0), "; ", CHAR(10)))

Parse text file to DGV, need to replace more then 1 consecutive periods

I am parsing a text file and importing it into a Data Grid View. The file is set up like so:
number 1 .......... 845.6
number 2 ....... 0.0001
col 1 col 2 col 3
1.233 4.55 1000
I need to get these values into a DGV then I can insert them into a Excel Template. I have everything working except for one line. the "number 1" line ends up all in one cell. I'll explain why.
I use the following code to process each line and sort of create a csv out of the data first.
TextLine = Regex.Replace(TextLine, " {2,}", " ")
TextLine = Replace(TextLine, " ", ",")
Since the data in the file is separated by more then one consecutive space on every line (except "number 1") I can just replace each occurrence with a comma and I get a nice result. What I was trying to do was replace consecutive periods with a space so "number 1" is separated from the value.
I have tried a few things:
TextLine = Regex.Replace(TextLine, "(.)\1{2,}", " ")
TextLine = Regex.Replace(TextLine, ".{2,}", " ")
the top one works, but also obviously gets rid of other characters that are consecutive. I also can't just remove periods, as some numbers have a decimal. I was thinking the solution might be using "Chr(46)" in that function, but I can't seem to make it work.
You need to escape the dot with a backslash so that it doesn't have a special meaning.
It looks like this is what you want:
Dim textLine As String = "number 1 .......... 845.6"
textLine = Regex.Replace(textLine, "\.{2,}", ",")
Console.WriteLine(textLine) ' outputs "number 1 , 845.6"
Or maybe Regex.Replace(textLine, "\.{2,}", " ") to replace two-or-more consecutive dots with a space.