适用于COUNTIF的Google表格模式匹配/正则表达式 [英] Google Sheets Pattern Matching/RegEx for COUNTIF

查看:223
本文介绍了适用于COUNTIF的Google表格模式匹配/正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于Google表格的模式匹配的文档没有帮助.我已经阅读和搜索了一段时间,但找不到此特定问题.也许我很难找到要搜索的正确术语,但这是问题所在:

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: ##-####

类别可以用零件号定义,即50-03##是一个产品类别,其余2位数字是特定于模型的.

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包含零件号,其格式设置为文本.如果我以其他方式对其进行格式设置,则由于Google表格认为我正在写日期或尝试进行算术运算,所以这些值显示不正确.)

(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.)

每次返回0,除非我更改为:

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?

推荐答案

如您所知,Wiktor提到COUNTIF仅支持通配符.

As you identified and Wiktor mentioned COUNTIF only supports wildcards.

虽然有很多方法可以做自己想做的事,但只能说2

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]*")))

这篇关于适用于COUNTIF的Google表格模式匹配/正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆