Best explained with an example:
I want to search the blue range and check if any of the cells contain any of the strings in the green range.
Ideally non-case-sensitive, and the search string could appear anywhere within the searched cells.
If...
search range: A1:A10
search key: B1:B3
... then use the following formula
=arrayformula(sum(if(regexmatch(textjoin(",",false,",",A1:A10,","),","&B1:B3&","),1,0)))>0
Feel free to read the documentation of the functions in question.
The basic idea here is that: we want to be able to join the search words into 1 string and apply arrayformula to individual search keys; and then, we want to search whole words.
So how do we easily search whole words? Your search words are divided by cells. So lets put , between them but also wrapping them. Now ","&search_key&"," marks a matched word -- not just a component of a search word.
The rest is doing and operation on array. Google Sheet unfortunately doesn't have functions like any or all. So the most (computationally) efficient thing to do is to use if (in comparison to alternatives like matrix multiplication or filter). The position of arrayformula doesn't matter here so you can just put it outside everything.
Here's another possible solution:
=ARRAYFORMULA(IF(BYROW(A5:C,LAMBDA(r,SUM(LEN(r))))=0,,BYROW(REGEXMATCH(A5:C,"\b"&TEXTJOIN("\b|\b",1,E1:E)&"\b"),LAMBDA(r,SUM(--r)>0))))
Note that this formula is entered once in D5 and it doesn't have to be dragged down.
result
With the recently added new functions, things can be done as easy as this.
The reference range A5:C7 and E1:E3 can be changed to match your needs.
=BYROW(A5:C7,LAMBDA(ROW,REGEXMATCH(JOIN(" ",ROW),JOIN("|",$E$1:$E$3))))
To make it a 'non-case-sensitive' search, you can add UPPER() to both of the reference range.
Since UPPER() itself is not an ArrayFormula, you'll have to wrap the whole thing with ArrayFormula(), so the outcome will look like this:
=ArrayFormula(BYROW(UPPER(A5:C7),LAMBDA(ROW,REGEXMATCH(JOIN(" ",ROW),JOIN("|",UPPER($E$1:$E$3))))))
Just found a problem, that if the green range contains empty cells, it may ruin the result, to get rid of this problem, I added QUERY() to the ref. range of green area like this:
=ArrayFormula(BYROW(UPPER(A5:C7),LAMBDA(ROW,REGEXMATCH(JOIN(" ",ROW),JOIN("|",UPPER(QUERY({E1:E3},"WHERE Col1 IS NOT NULL")))))))
Or, we can include the 'non-case-sensitive' argument into regex2 like this:
=BYROW(A5:C7,LAMBDA(ROW,REGEXMATCH(JOIN(" ",ROW),"(?i)"&JOIN("|",QUERY({E1:E3},"WHERE Col1 IS NOT NULL")))))
use:
=INDEX(REGEXMATCH(FLATTEN(QUERY(TRANSPOSE(A5:C7),,9^9)),
"(?i)\b"&TEXTJOIN("|", 1, E1:E)&"\b"))
I'm extracting text from filename cells into separate metadata field cells. So far I have done this successfully using the REGEXTRACT formula, as seen below.
=REGEXEXTRACT(A1, "TILEABLE|ROOM|MAIN|FLOORSHOT|SWATCH|ANGLED")
However some metadata fields that include multiple words require that a space or other character be placed between words. I'm trying to figure out how to use SUBSTITUTE or REPLACE in conjunction with REGEXTRACT to find a phrase and replace it with a version with something different. Ex. Replace "TOPDOWN" with "Top Down" or replace "1TO1" with "1-to-1).
Depending on your purpose one formula might be better than other. If you want to list in a column the substituted values of this string you could chain the number of phrases you want using SUBSTITUTE and REGEXTRACT.
This will return all the phrases you are looking for and substitute them to then use the formula TRANSPOSE to take this range and display it in a columns (as it normally would be displayed in a row and only a single value). This is a simple example:
=TRANSPOSE({SUBSTITUTE(REGEXEXTRACT(A1,"TOPDOWN"),"TOPDOWN","Top Down"),SUBSTITUTE(REGEXEXTRACT(A1,"SHIRTS"),"SHIRTS","Shirts1")})
try:
=SUBSTITUTE(SUBSTITUTE(REGEXEXTRACT(A1,
"TOPDOWN|1TO1|TILEABLE|ROOM|MAIN|FLOORSHOT|SWATCH|ANGLED"),
"TOPDOWN", "Top Down"),
"1TO1", "1-to-1")
Question!
I have a few hundred cells with text strings that also contain numbers within them. I want with a formula to add text before and after each presence of a number.
So for example: "Find 2 dogs, 3 times". I'd want to turn this to
"Find [insertedtextbefore]2[insertedtextafter] dogs', [insertedtextbefore]3[insertedtextafter] times".
Thanks!
You want to put [insertedtextbefore] to before the number in the text of the cell.
You want to put [insertedtextafter] to after the number in the text of the cell.
As a sample value, you want to achieve as follows.
From
Find 2 dogs, 3 times
To
Find [insertedtextbefore]2[insertedtextafter] dogs, [insertedtextbefore]3[insertedtextafter] times
You want to achieve this using the built-in functions of Google Spreadsheet.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Sample formula:
=ARRAYFORMULA(REGEXREPLACE(A1:A5," (\d+) ", " [insertedtextbefore]$1[insertedtextafter] "))
In this case, the values are put to the cells "A1:A5".
Result:
References:
REGEXREPLACE
ARRAYFORMULA
If I misunderstood your question and this was not the direction you want, I apologize.
I have ListGrid in smartGWT populated with fields and information. Some of the columns have sentences. I was wondering if it was possible to highlight all occurrences of a specific keyword. For example: If I had a sentences "The cat was fluffy" and "The cow jumped over the moon and I wanted to find all occurrences of "the", then my columns would show: "The cat was fluffy" and "The cow jumped over the moon".
I know that you can use the editHilites() method to highlight the entire cell of the column, but I want to highlight individual words within the column. Is there an easy/feasible way to do this in smartGWT?
The text you are writing in the field is Html, so I think you can use your css...
I found a way to use setCellFormatter to create a cellFormatter to search through and find what I wanted to highlight.
I have created a google sheet to schedule appointments for a clinic. I am looking to find a method which will highlight the cell or row based on a client name? This can be based off a script or separate google sheet.
For example, I want the following names to be highlighted if they are entered.
John Smith
Susan Johnson
Ted Jones
When someone enters their name in the Column (Name), then that row or cell will be highlighted with a color.
Any help would be greatly appreciated. Thank you
Go to Format -> conditional formatting and then set the rules you want for the range of cells where you want that highlighting rule to be applied. You can highlight if the cell is blank/ not blank, or if the cell contains specific text that you will need to stipulate.
You'll also want to be sure that they spell the name correctly so that the conditional formatting actually works. If you know all the names in advance, you can even create a dropdown list using the data validation tool to prevent typos.
Data > Validation > List from a range or items