I'm trying to count how many times the text appeared in a range and it is possible that the text can appear multiple times in a single cell.
This is the formula that I'm using and it gives me the result that I need.
=ArrayFormula(SUM(LEN(DATA!M2:M10)-LEN(SUBSTITUTE(DATA!M2:M10,"HELLO","")))/LEN("HELLO"))
But I need to add some filters and I try to do it like the formula below but I'm just getting #N/A Error: Argument must be a range.
=ArrayFormula(SUMIFS(LEN(DATA!M2:M)-LEN(SUBSTITUTE(DATA!M2:M,"HELLO","")), DATA!E2:E, "TEST" , DATA!C2:C, ">=" & D2, DATA!C2:C, "<=" & D3)/LEN("HELLO"))
SUMIFS is not capable for this. try:
=INDEX(SUM(LEN(REGEXREPLACE(SUBSTITUTE(IF(
(Data!E2:E="TEST")*(Data!C2:C*1>=D2)*(Data!C2:C*1<=D3), Data!A2:A, ),
"HELLO", "♦"), "[^♦]", ))))
I have a list of 7000+ keywords about HVAC repair and I've managed to isolate all the unique words used in each keyword (3000+ unique words). I will be picking out the words that we don't need (such as car ACs) and then use that list to essentially make a "banned" word list. How can I then use a query to "select A where A does not contain [banned word range]"?
I tried =query(A:A, "select A where A does not contain B") but I don't think that it's that easy. (B is the banned word range)
Here's my ongoing project:
https://docs.google.com/spreadsheets/d/1G5tz4Ap6WRJT2ZXJm44vOxueIOJdO32Kcti1rkudB2I/edit?usp=sharing
you can do it like this:
=QUERY(A2:A, "where not A matches '^"&TEXTJOIN("$|^", 1, B2:B)&"$'", 0)
for "true contain" use:
=FILTER(A2:A, NOT(REGEXMATCH(A2:A, TEXTJOIN("|", 1, B2:C))))
this is a bit longer but solves every possible fail you may encounter:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(IFERROR(
IF(REGEXMATCH(IFERROR(SPLIT(A2:A, " ")), "^"&TEXTJOIN("$|^", 1, B2:C)&"$")=FALSE,
SPLIT(A2:A, " "), "♦"))),,999^99)), "where not Col1 contains '♦'", 0))
Right now I have these data and I'm trying to filter out the data containing in cell C3, C4, etc.
I have no problem filtering the regexmatch data for 1 cell as shown below
but I'm unable to do regexmatch for more than 2 cells like so for example, it seems like I'm unable to make the pipework between cells as I'll get parse error, I tried adding in "C3|C4" too.
and
The wanted output that I wanted is as below but I could only hardcode the containing text in which isn't what I'm looking for. I'm hoping that I could have some tips to regexmatch the text in more than 1 cell such that it could regexmatch the text in cell C3(Apple) and C4(Pear) and show the wanted output.
you need to use TEXTJOIN for dynamic list in C column:
=IF(TEXTJOIN( , 1, C3:C)<>"", FILTER(A2:A, REGEXMATCH(LOWER(A2:A),
TEXTJOIN("|", 1, LOWER(C3:C)))), "no input")
You may use
=IF(C3<>"", FILTER(A2:A,REGEXMATCH(A2:A, TEXTJOIN("|", TRUE, C3:C4) )), "no input")
Or, you may go a step further and match Apple or Pear as whole words using \b word boundaries and a grouping construct around the alternatives:
=IF(C3<>"", FILTER(A2:A,REGEXMATCH(A2:A, "\b(?:" & TEXTJOIN("|", TRUE, C3:C4) & ")\b")), "no input")
And if you need to make the search case insensitive, just append (?i) at the start:
=IF(C3<>"", FILTER(A2:A,REGEXMATCH(A2:A, "(?i)\b(?:" & TEXTJOIN("|", TRUE, C3:C4) & ")\b")), "no input")
See what the TEXTJOIN documentation says:
Combines the text from multiple strings and/or arrays, with a specifiable delimiter separating the different texts.
So, when you pass TRUE as the second argument, you do not have to worry if the range contains empty cells, and the regex won't be ruined by extraneous |||.
Test:
Basically, I am trying to find a way to search through a list of phrases and highlight/extract or identify any phrase or cell that contains a phrase or word from a separate column/list.
To put this into context, I have a list of "search terms" that have triggered my Google ads, this list contains phrases or expressions that people have entered into the google search engine.
I also have a list of "negative keywords" that I have used to block ads from showing when certain words or phrases are entered into Google. For example, if I have the word "nursery" in my negative keyword list, then it should stop an ad from showing if someone enters the phrase "best nursery near me"
I have then placed both these lists within an excel spreadsheet in separate columns, so one column has the search terms, and another column has the negative keywords.
What I want to do is search through all the search terms and highlight a cell it if any word or phrase within that cell matches the phrase from the negative keywords list. In the example above, the cell containing the phrase "best nursery near me" would be highlighted or extracted as the phrase "nursery" is in the negative keyword list.
REGEXMATCH in google sheets does do this, however, I don't know of a way for it to select multiple expressions, it does allow multiple expressions but only by doing say (A1|A2|A3), the issue with this is I have over 1000 cells so would want a way to select all of them at once, like (A1:A1000)
here is a link to the Google Sheet, if possible I'd prefer to be able to do it in Excel. https://docs.google.com/spreadsheets/d/1yLTswjrpwf2owhX4YxPavUY441WlQsnzv3StoP-ilmc/edit?usp=sharing
There is a much simpler way to do this. Don't overcomplicate things.
Say you want to search for a match from a list of cities.
Put your list of cities in one tab.
Make them into lowercase for easier lookup since search terms are all in lowercase. You can do this by adding a new column and using the LOWER function.
Go back to your cell that has the list of search phrases.
In any blank cell out of the way (off to the side on the top row is a good place) put this formula:
CITY LIST FORMULA: =TEXTJOIN("|",1,'vlookup city'!B$2:B$477) (if your tab is named 'vlookup city' and your cities are in column B of that tab)
Add a new column next to your search terms, or pick an existing one where you want to put your "match found" info.
In that new column, add this formula (if your data starts in row 4 and you put the City List formula in cell G3:)
=REGEXMATCH(A4,G$4)
Fill the formula all the way down your list. You can double-click the little blue square in the bottom right corner of the cell, or grab-and-drag all the way to the bottom of the list.
Ba-ding! It will search for any one of those city names, anywhere in your search phrase.
If the search phrase contains at least one matching term, it will return "True."
You can then add extra features on your formula to make it return something else. For example:
=IF(REGEXMATCH(A4,G$4), "match found", "no match found")
This is a super lightweight solution that won't slow your sheet down too much and is easy to use.
enter image description here
https://docs.google.com/spreadsheets/d/1XAIDB98r2CGu7hL3ISirErDPNlgT6lVt-TCG0qI1uTE/edit?usp=sharing
=ARRAYFORMULA(IF(REGEXMATCH(A2:A, TEXTJOIN("|", 1, C:C)), A2:A, ))
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(A2:A, TEXTJOIN("|", 1, C:C))))
=ARRAYFORMULA(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IFERROR(
SPLIT(A2:A, " ")), "^"&TEXTJOIN("|^", 1, C:C)), A2:A, )),,999^99))))
=ARRAYFORMULA(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IFERROR(
SPLIT(A2:A, " ")), "^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99))))
=ARRAYFORMULA(IF(IF(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IFERROR(
SPLIT(A2:A, " ")), "^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99)))<>"",
TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IFERROR(
SPLIT(A2:A, " ")), "^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99))),
TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(A2:A,
"^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99))))<>"",
IF(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IFERROR(
SPLIT(A2:A, " ")), "^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99)))<>"",
TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IFERROR(
SPLIT(A2:A, " ")), "^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99))),
TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(A2:A,
"^"&TEXTJOIN("$|^", 1, C:C)&"$"), A2:A, )),,999^99)))),
TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(IF(REGEXMATCH(A2:A, "\s"), A2:A, ),
TEXTJOiN("|", 1, C:C)), A2:A, )),,999^99)))))
How can I replace a list of values like
married
single
non
married
couple
to a list like this using a regular expression
Status 2
Status 1
non
Status 2
couple
? I know can match each group by something like this
/(married|single)/gm
and that I can address the matched group by $1, $2, ... . But how can I address and/or if-else the group-value in the replace-part to acutally translate the values?
Edit
Let's say I have the values to replace in a MariaDB-colum marital in myTable. Then I can do something like
SELECT
marital,
REGEXP_REPLACE(REGEXP_REPLACE(marital,
"married", "Status 2")
, "single", "Status 1")
FROM myTable
To get the desired result. But Is there a way to do this with just one REGEXP_REPLACE?
Thanks for your help!
You cannot do it with a single REGEXP_REPLACE because MariaDB doesn't support the required features in the third parameter.
You may do it using PHP with arrays: http://php.net/manual/en/function.preg-replace.php
or with callback: http://php.net/manual/en/function.preg-replace-callback.php
You may do it using Perl: How to replace a set of search/replace pairs?