Google Sheets Pattern Matching/RegEx for COUNTIF

家住魔仙堡 提交于 2019-12-05 12:35:06

问题


The documentation for pattern matching for Google Sheets has not been helpful. I've been reading and searching for a while now and can't find this particular issue. Maybe I'm having a hard time finding the correct terms to search for but here is the problem:

I have several numbers (part numbers) that follow this format: ##-####

Categories can be defined by the part numbers, i.e. 50-03## would be one product category, and the remaining 2 digits are specific for a model.

I've been trying to run this:

=countif(E9:E13,"50-03[123][012]*")

(E9:E13 contains the part number formatted as text. If I format it any other way, the values show up screwed up because Google Sheets thinks I'm writing a date or trying to do arithmetic.)

This returns 0 every time, unless I were to change to:

=countif(E9:E13,"50-03*")

So it seems like wildcards work, but pattern matching does not?


回答1:


As you identified and Wiktor mentioned COUNTIF only supports wildcards.

There are many ways to do what you want though, to name but 2

=ArrayFormula(SUM(--REGEXMATCH(E9:E13, "50-03[123][012]*")))

=COUNTA(FILTER(E9:E13, REGEXMATCH(E9:E13, "50-03[123][012]*")))


来源:https://stackoverflow.com/questions/40515469/google-sheets-pattern-matching-regex-for-countif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!