我有一个已解析的字段,我需要计算给定字符串在其中出现的次数。这看起来相对简单,但我一直在搜索相扑文档,现在我不确定这是否可能。请帮忙!
最佳答案
我有一个使用 replace()
的 hacky 解决方案的想法正则表达式变体。
如 inputField
是您的输入字段,您想计算次数 is
发生在 inputField
, 然后
| "This is a very hacky solution which might get you in trouble" as inputField
| replace(inputField, /is/, "@") as matched
| replace(matched, /[^@]/, "") as skipTheRest
| length(skipTheRest) as finalCount
解决方案假设 @
不存在于输入字段中。免责声明:我目前受雇于 Sumo Logic。
关于相扑逻辑 : Count every matching string within a field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62782151/