首页 > 其他分享 >正则分类统计

正则分类统计

时间:2023-03-08 15:23:17浏览次数:25  
标签:Function End res s1 分类 正则 ar split 统计

Dim d As Object
Sub main()
    Set d = CreateObject("scripting.dictionary")
    With Sheet1
        .Range("c1").CurrentRegion = ""
        ar = .Range("a1").CurrentRegion
        For x = 1 To UBound(ar)
            s = ar(x, 1)
            If InStr(s, ",") > 0 Then s = Replace(s, ",", ",")
            sp = Split(s, ",")
            For i = 2 To UBound(sp)
                ar_res = split_by_rege(sp(i))
                If Not d.exists(ar_res(0)) Then
                    d(ar_res(0)) = ar_res(1)
                Else
                    k = d(ar_res(0))
                    k = k & "," & ar_res(1)
                    d(ar_res(0)) = k
                End If
            Next
        Next
        r = 1
        .Range("c1").Resize(1, 3) = Array("品种", "数量", "备注")
        For Each a In d.keys
            r = r + 1
            .Cells(r, 3) = a
            .Cells(r, 4) = second_split(d(a))
            If InStr(a, "鱼") > 0 Then .Cells(r, 5) = Replace(d(a), ",", "+")
        Next
        .Range("c1").CurrentRegion.Borders.LineStyle = 0
        .Range("c1").CurrentRegion.Borders.LineStyle = 1
        .Cells.Interior.ColorIndex = 0
        For j = 1 To r
            If j Mod 2 = 1 Then .Range(Cells(j, 3), Cells(j, 5)).Interior.ColorIndex = 34
        Next
    End With
    Set d = Nothing
End Sub

Function second_split(s)
    If InStr(s, ",") > 0 Then
        spl = Split(s, ",")
        For x = 0 To UBound(spl)
            tem_res = split_by_rege3(spl(x))
            tem = tem + tem_res(0) * 1
        Next
        second_split = tem & tem_res(1)
    Else
        second_split = s
    End If
End Function

Function split_by_rege2(s)
    With CreateObject("vbscript.regexp")
        .Pattern = "(\d*\.?\d*)([一-龥]+)"
        .Global = True
        .IgnoreCase = True
        .MultiLine = False
        Set mh = .Execute(s)
        s1 = mh(0).SubMatches(0)
        s2 = Replace(s, s1, "")
    End With
    split_by_rege2 = Array(s1, s2)
End Function

Function split_by_rege3(s)
    With CreateObject("vbscript.regexp")
        .Pattern = "(\d*\.?\d*)([一-龥]+)"
        .Global = True
        .IgnoreCase = True
        .MultiLine = False
        Set ma = .Execute(s)
        s1 = ma(0).SubMatches(0)
        s2 = ma(0).SubMatches(1)
    End With
    split_by_rege3 = Array(s1, s2)
End Function

Function split_by_rege(s)
    With CreateObject("vbscript.regexp")
        .Pattern = "([一-龥]+)|(\d*\.?\d*(斤|条))"
        .Global = True
        .IgnoreCase = True
        .MultiLine = False
        Set mh = .Execute(s)
        s1 = mh(0).SubMatches(0)
        s2 = mh(1).SubMatches(1)
    End With
    split_by_rege = Array(s1, s2)
End Function

  

标签:Function,End,res,s1,分类,正则,ar,split,统计
From: https://www.cnblogs.com/eyunkeji/p/17192097.html

相关文章

  • 记录一下C#中使用正则表达式
    privatestaticvoidMain(string[]arg){vartext="";//文本读取器using(TextReaderreader=newStreamR......
  • Power BI统计发生频率(次数)排名
    业务需求如图所示,存在一张表'qcissue'(质检异常表),分别有字段date(发生日期),partnumber(零件号)和checkitem(检查项目),利用PowerBI统计每个月每一个检验项目次数(发生频率)的排......
  • 【element-ui】 textarea输入框数据统计遮挡输入文字
    原代码问题:“4/255”默认背景为白色已超出文本输入框,遮住部分上border,当文字到达右侧时会遮住部分文字,且无法点击该部分解决方案:背景透明色,文字放到右下角代码<el-......
  • Linux - 性能统计命令汇总
    监测服务器性能的基本命令通过CPU、内存、I/O这三方面,回顾Linux系统下,服务器性能监测命令以及问题排查思路。CPU查看CPU软硬件信息$cat/proc/cpuinfoproces......
  • 常用正则表达式
     1、数字1、数字:^[0-9]*$2、n位的数字:^\d{n}$3、至少n位的数字:^\d{n,}$4、m-n位的数字:^\d{m,n}$5、零和非零开头的数字:^(0|[1-9][0-9]*)$6、非零开头的最多......
  • LeetCode题分类
    一.数组题目分类题目编号数组的遍历485、495、414、628统计数组中的元素645、697、448、442、41、274数组的改变、移动453、665、283二维数组及滚动数组118、119......
  • 从国家统计局网站爬取省级到村级别的行政区划代码(2022最新)
    importcn.hutool.http.HttpUtil;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.IOException;importjava.io.InputStreamReader;importj......
  • .NET 使用 Coverlet 统计单元测试覆盖率
    代码覆盖率(Codecoverage)是指在软件测试中测试用例执行时覆盖的代码量与总代码量的比例。代码覆盖率是软件测试中一个重要的指标,它对于保障软件质量、提高软件可靠性和可维......
  • BOSHIDA 模块电源的分类(三)
    BOSHIDA三河博电科技模块电源的分类(三)AC/DC电源模块的基本原理是从交流源中获取电压,然后由整流器转换为直流电压,且输出能量比输入的电压高,从而达到电路输出直流电压、......
  • C# 正则表达式(Regex)
    C#正则表达式(Regex) 正则表达式是形成搜索模式的一系列字符。正则表达式可用于检查字符串是否包含指定的搜索模式。也可以进行字符串的替换和提取。本文主要......