Count all nonwhite character - google-sheets

I'm trying to count number of items in given table. But table may consist cell with different whitespace chars.
I would like to do count, but only consider cell with letters and number.
I was trying to do
COUNTIF(<range>, "?*")
Is there any list of available wildchars provided by google-spreadsheet ? I need "*" but matching only numbers and letters.

Maybe use regexmatch to match letters or digits ?
=ArrayFormula(sum(N(regexmatch(A2:L18&"", "\w|\d"))))
Change the range to suit.
See also this spreadsheet

Related

Capitalize only words with more than 2 characters on Google Sheets

How can I capitalize only words with more than a specific count of characters? Google Sheets formula PROPER capitalizes all the words without any exclusions. For example, I would like to omit the capitalization of an acronym such as "PC" or "RAM" that is contained within a string in a cell.
Capitalize All and exclude from a list
To be able to PROPER()/Capitalize the input of words and exclude others:
Use this formula, but first we need the excluded list "Acronyms excluded".
=ArrayFormula(IF(
REGEXMATCH(TEXTJOIN("^_~",,UNIQUE($D$2:$D)), UPPER(A2:A))<>TRUE,PROPER(A2:A),A2:A))
Capitalize only words more than 2 charachters long
=ArrayFormula(IF(A2:A="",,
IF(LEN(UPPER(A2:A))<=2,
UPPER(A2:A),PROPER(A2:A))))
I may have been overthinking this by a mile, but try:
Formula in B1:
=INDEX(SUBSTITUTE(TEXTJOIN("",0,IF(LEFT(SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|"))="♣",SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|"),PROPER(SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|")))),"♣",""))
The point here is that \b(RAM|[A-Za-z]{1,2})\b would capture any 1-2 character word made of word-characters between word-boundaries or RAM. Now you can add any exclusion into the alternation of the pattern through concatenating more |. The replacement includes a backreference to the capture group to encapsulate the substring between a delimiter to split on and a leading unique character. The IF() will then check whether or not any element from the resulting SPLIT() needs to be processed with Proper() or not.
Note: Word-boundaries like \b may not be safe when you'd have data like hello-pc and you'd want this to be processed with PROPER(). A small adjustment to the formula is then needed.

Extract dollar amount in sheets text cell

Ideally what I'm looking for is to get the dollar amount extracted no matter the format.
Sheet link:
https://docs.google.com/spreadsheets/d/1drTPlnQmVTsbUXwJDfQr7DnHjSbnGx-fLthad6KxfM8/edit?usp=sharing
Delete everything from Column B, including the header. Then place the following formula in cell B1:
=ArrayFormula({"Header"; IF(A2:A="",,VALUE(IFERROR(REGEXEXTRACT(A2:A,"\$(\d+\.?\d*)"))))})
You may change the header text within the formula as you like.
If a cell in A2:A is blank, the corresponding cell in B2:B will be left blank as well.
Otherwise REGEXEXTRACT will look for a pattern that begins with a literal dollar sign. The parenthesis within the quotes denote the beginning and end of a capture group (i.e., what will be returned if found) following that literal dollar sign. The pattern \d+\.?\d* means "a group of one or more digits, followed by zero or one literal period symbols, followed by zero or more digits."
IFERROR will cause null to be rendered instead of an error if such a pattern is not able to be extracted.
VALUE will convert the extracted string (or null) to a real number.
If you would prefer that null be returned instead of 0 where no pattern match is found, you can use the following variation of the formula instead:
=ArrayFormula({"Header"; IFERROR(VALUE(IFERROR(REGEXEXTRACT(A2:A,"\$(\d+\.?\d*)"),"x")))})
If your strings may include numbers with comma separators, use the following versions of the above two formulas, respectively:
=ArrayFormula({"Header V1"; IF(A2:A="",,VALUE(IFERROR(REGEXEXTRACT(SUBSTITUTE(A2:A,",",""),"\$(\d+\.?\d*)"))))})
=ArrayFormula({"Header V2"; IFERROR(VALUE(IFERROR(REGEXEXTRACT(SUBSTITUTE(A2:A,",",""),"\$(\d+\.?\d*)"),"x")))})
try:
=INDEX(IFNA(REGEXEXTRACT(A2:A, "\$(\d+.\d+|\d+)")*1))

Filter a string based on a variable number of substrings in Google Sheets

I have a cell with a variable number of substrings separated by a comma.
To search:
"first,second,third"
"primero,segundo,tercero,cuarto"
"eins,zwei"
and I have a column with many strings that are composed by some of the substrings:
Column with full items
"first,second,third,fourth"
"primero,segundo,tercero,cuarto,quinto"
"primero,tercero,cuarto"
"eins,zwei,drei"
...and so on...
I would like to find the items of the Column above which has the substrings to be searched. Not a big issue when the amount of substrings is fixed but when it varies it becomes harder. I have a horrible formula that counts the number of commas and then it uses IF for each amount of substrings to search and several FIND(index(SPLIT(A4,","),2) for each substring. The formula is gigant and hard to handle.
Can you think of a better way of doing it?
Here there is an example of what I would like to do. The blue cells are the ones that should have the formula.
https://docs.google.com/spreadsheets/d/1pD9r4JF48cVSNGqA4D69lSyasWxTvAcOhWWu1xW2mgw/edit?usp=sharing
Thanks in advance!
Thank you all for your help! In the end, I used the QUERY function.
=QUERY(E:F,"select E where F contains '" & textjoin("' AND F contains '",TRUE,split(A2,",")) &"'" )
If you are interested, you can see the solution applied in the original spreadsheet :)

Google Sheets Split / Trim From First Letter

I have a list of IDs like this :
40316C1
40316433D112
4316C1
4Z2
40316B2
40310
I would like to return the IDs like this:
40316
40316433
4316
4
40316
40310
Basically, from the first alphabet Character, Trim or Split the rest on the right.
Can I do this in Google Sheets?
You can do it with REGEXEXTRACT
Sample:
=REGEXEXTRACT(A1,"\d{1,20}")
This formula will evaluate the first 20 characters of the IDS (you can change 20 to ahigher number if necessary`
\d means that the formula will extract only numbers from the IDs - until it finds the first non-number.
UPDATE:
The case of no text characters existing in the cell can be caught with =IFERROR
=IFERROR(REGEXEXTRACT(A5,"\d{1,20}"),A5)+0

Google spreadsheets conditional formatting if text contains numbers

I have a sheet containing my weekly schedule. Only school cells have a room number in it, so how do I format the cells to color only the ones that contain a number.
note: Actually, the room number is a number in range(A:E) followed by a three digits number in range(000:499). Ex.:(A433, B166, D254)
I tried: Text contains"(A:F)(000:444)" but it didn't work.
EDIT:
For some reason, "=REGEXMATCH(B2, "[A-F][0-9]{3}")" worked. Could anyone tell me why? I tried replacing B2 by B1, but then it didn't work. Does it have anything to do with the fact that B1 is a weekday, and so does not contain REGEXP(B1,"[A-F][0-9]{3}) returned false.
What seemed more logical to me was "=REGEXMATCH(B2:F22, "[A-F][0-9]{3}")" To apply this function in range B2 to F22. What am I missing here?
In order to match patterns, you'll need to use regular expressions. Since the standard Conditional Formatting options don't include regular expressions, you'll need to choose "Custom formula is" and then use REGEXMATCH, which returns a Boolean value.
If you really want to look for the specific room number format you mentioned, then you would use the formula:
=REGEXMATCH(A1, "[A-E][0-9]{3}")
But if you just want to look for any numbers, you can use
=REGEXMATCH(A1, "[0-9]+")
In both cases, the text you're checking is in cell A1
You might try Conditional Formatting with a custom formula rule of the type:
=if(isnumber(A1),1,regexmatch(A1,"\d"))
The above was an attempt to respond to:
Google spreadsheets conditional formatting if text contains numbers
A more particular fit for the stated room number style would be:
=REGEXMATCH(A1,"[A-F]\d\d\d")
where the first character is any of the first six letters of the alphabet, if capitalised, followed by three instances of any number.

Resources