I have a list of text on col A and I like to run a switch based on if there is a regexmatch in that cell..
A1 = "https://www.amazon.es/dp/B07PHPXHQS/ref=gw_es_desk_h1_aucc_cr_vd20?pf_rd_p=b1bd6d90-90a7-419a-8a6e-8c943ef52b62&pf_rd_r=XKJEDGQX6TSJ91JF0B6Y"
=switch(A1,REGEXMATCH(A1, "amazon."),"amazon",REGEXMATCH(A1, "lifehacker."),"LFH",REGEXMATCH(A1, "engadget."),"ENG","other")
If the link is amazon.com/whatever it should return "amazon" and so on
I get no error.. but I always get "other" as if regexmatch would not work here.
Any other way to do this?
Try this:
=ifs(
REGEXMATCH(A1,"this"),"that",
REGEXMATCH(A1,"this2"),"that2",
REGEXMATCH(A1,"this3"),"this3",
TRUE,elseGoesHere)
That last line is the ticket don't forget its a new case,value pair so don't forget the preceding coma
It's kind of a category error because in your switch statement you are trying to compare the whole string in A1 to the result of the REGEXMATCH function calls which would actually be TRUE, FALSE and FALSE. To make this work using a switch statement you would need to do something like this:
=iferror(switch(regexextract(A1,"amazon.|lifehacker.|engadget."),"amazon.","amazon","lifehacker.","LFH","engadget.","ENG"),"other")
but I suspect that there are more elegant ways of doing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With