Regex for array in Google Sheets - google-sheets

How do I remove non-numerical characters from a filter in Google Sheets?
I have a function that spits out matching phone numbers into up to 3 subsequent columns. I would like to eliminate non-number characters and a prevailing 1 if there is one, possibly using Regex.
=array_constrain(transpose(filter(People!H:H,People!B:B=A10)),1,3)

=ARRAYFORMULA(IFERROR(REGEXREPLACE(TO_TEXT(A1:A), "\D+|^1", "")))

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.

How to cut out substrings (paths) of a URL in Google Spreadsheets?

I want to cut out substrings from this url XYZ.com/de/haus/dach/ and put the values each in its own columns in Google Spreadsheet.
With this url example:
Column A should be "de"
Column B should be "haus"
Column C should be "dach"
How can I do that?
Remove the characters before the first /. This can be done in a number of ways, including REGEXREPLACE or through a combination of RIGHT, LEN and FIND.
SPLIT the resulting string.
=SPLIT(RIGHT(A1,(LEN(A1)-(FIND("/",A1)))),"/")

Random Cells From A List In Google Sheets

Sample
Code:
=ArrayFormula((VLOOKUP(QUERY(UNIQUE(RANDBETWEEN(ROW(INDIRECT("A1:A"&COUNTA(A:A)*10))^0;COUNTA(A:A)));"limit 4");{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A;A:A<>"")};2;0)))
I'm trying but got this error,
test 1
Can anyone tell what's wrong? To make my code
to work as in the first picture
error in #REF!
VLOOKUP evaluates outside the range bounds.
im try change code
=ArrayFormula((VLOOKUP(QUERY(UNIQUE(RANDBETWEEN(ROW(INDIRECT("A1:A"&COUNTA(A:A)*10))^0,COUNTA(A:A))),"limit 4"),{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A,A:A<>"")},1,0)))
but number
solution for that?
=ARRAYFORMULA(VLOOKUP(FLOOR(RANDARRAY(5)*COUNTA(A2:A)),{SEQUENCE(COUNTA(A2:A),1,0),A2:INDEX(A2:A,COUNTA(A2:A))},2))
Create 5 random integers using RANDARRAY between 0(inclusive) and number of entries in A2:A(i.e., COUNTA)(exclusive).
Create a artificial side by side array({arr1,arr2}) of SEQUENCE of numbers (from 0) and actual values in A2:A
VLOOKUP the random integers in the created artificial array to give random values in A:A
If you're in locales that use comma as decimal separators, The artificial array should be created using \ instead of ,({arr1\arr2}).
=ARRAYFORMULA(VLOOKUP(FLOOR(RANDARRAY(5)*COUNTA(A2:A));{SEQUENCE(COUNTA(A2:A);1;0)\A2:INDEX(A2:A;COUNTA(A2:A))};2))
On the first formula
{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A;A:A<>"")}
replace the semicolon ; between INDIRECT() and FILTER() by a backslash \ as using a semicolon appends the results of FILTER to the results of INDIRECT but you are looking to put the results of each function on their own column. Please note that this formula is using semicolons as argument separator.
On the second formula replace the semicolon ; between INDIRECT() and FILTER() by a comma , (and replace the third argument of VLOOKUP, 1, by 2. Please note that this formula is using commas as argument separators.
Explanation
Commas are used as argument separator on spreadsheets that use dot as decimal separator (=SUM(1,2,3)) but also use commas as columns separator on arrays ({"a","b"})
Semicolons are used as argument separator on spreadsheets that use comma as decimal separator (=SUM(1;2;3)). On these spreadsheets, backslashes are used as columns separator on arrays ({"a"\"b"});
References
Using arrays in Google Sheets

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

Count all nonwhite character

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

Resources