VB6学习——正则的使用
1. 引用 Microsoft VBScrip Regular Expressions 5.5
Function FXMenu(txt As String, Optional isTip As Boolean = True)
1 On Error GoTo Err_FXMenu'-------------------------------------Dim RE As New RegExpDim colMatches As MatchCollectionDim colMatches2 As MatchCollectionDim colMatches3 As MatchCollectionDim mm As IntegerDim menuTmp As String, FuMenu As String, whoUse As String2 RE.Global = True'为空则退出
3 If Trim(txt) = "" Then
4 If isTip Then MsgBox "文本内容为空,分析终止!", vbOKOnly + vbInformation, "分析提示"
5 Exit Function
6 End If7 txt = Replace(txt, vbCrLf, "") '删除换行
8 Debug.Print txt'分析 子级 菜单
9 RE.Pattern = "Begin VB.Menu (\S+)\s*Caption = \""(\S+)\""\s*Index = (\d+)"10 Set colMatches = RE.Execute(txt)'Debug.Print colMatches.Count
11 If colMatches.Count <= 0 Then Exit Function
12 Frm_FXConfig.Text_Menu.Text = "": Frm_FXConfig.Text_MenuCode.Text = ""
13 For mm = 0 To colMatches.Count - 114 If colMatches(mm).SubMatches(0) <> menuTmp Then '换了一组菜单'查询 该组子菜单的 父菜单
15 RE.Pattern = " Begin VB.Menu (\S+)\s* Caption = \""\S+\""\s*Begin VB.Menu " & colMatches(mm).SubMatches(0)
16 Set colMatches2 = RE.Execute(txt)
17 FuMenu = "": whoUse = ""
18 If colMatches2.Count > 0 Then
19 FuMenu = colMatches2(0).SubMatches(0) '子菜单的父菜单'根据 父菜单 找谁调用了这个 子菜单
20 RE.Pattern = "Private Sub (\S+)_[\S\s]{1,300}PopupMenu " & FuMenuSet colMatches3 = RE.Execute(txt)
22 If colMatches3.Count > 0 Then
23 whoUse = colMatches3(0).SubMatches(0)
24 End If
25 End If
26 menuTmp = colMatches(mm).SubMatches(0)
27 End If28 Frm_FXConfig.Text_Menu.Text = Frm_FXConfig.Text_Menu.Text + FuMenu & " --> " & whoUse & " " & colMatches(mm).SubMatches(0) & " " & colMatches(mm).SubMatches(1) & " " & colMatches(mm).SubMatches(2) & vbCrLf'查找 哪个组件调用了这个 右键菜单' Begin VB.Menu (\S+)\s*.*\s*Begin VB.Menu Mnu_PopHLBs'RE.Pattern = "Private Sub ([\S]+)_[\s\S]+PopupMenu " & D'自动生成代码29 Next
VBA Excel 正则的使用
Option ExplicitSub ExtractColorAndNumber()Dim i As IntegerDim lastRow As LongDim regex As ObjectSet regex = CreateObject("VBScript.RegExp")'regex.Global = TruelastRow = Cells(Rows.Count, 1).End(xlUp).Row' 定义正则表达式Dim colorPattern As StringcolorPattern = ".{1,2}色"Dim numberPattern As StringnumberPattern = "\d+.?\d+#?(AWG)?"For i = 1 To lastRow' 提取颜色Dim colorMatches As Objectregex.Pattern = colorPatternSet colorMatches = regex.Execute(Cells(i, 2).Value)If colorMatches.Count > 0 ThenCells(i, 6).Value = Replace(colorMatches.Item(0), "-", "")Cells(i, 6).Value = Replace(Cells(i, 6).Value, "色", "")End If' 提取数字Dim numberMatches As Objectregex.Pattern = numberPatternSet numberMatches = regex.Execute(Cells(i, 2).Value)If numberMatches.Count > 0 ThenCells(i, 7).Value = numberMatches.Item(0)End IfNext i
End Sub
VB6学习——正则的使用相关推荐
- 由浅入深的正则表达式教程,简单快速学习正则
文章目录 前言 正则表达式是什么 字符串匹配方法 match() 字符串检查方法 test() 正则表达式语法 ^ 和 $ 的用法和区别详解 限定符 普通字符 特殊字符 元字符 运算符优先级 常用的正 ...
- Python 学习 正则re解析详解
一.学习正则的目的 应用场景举例: ① 提取xml文件里的信息 有些xml文件应用编辑器的一些读取库可能无法实现效果,但是用正则的话基本上能解决绝大多数参数匹配问题.如以下提取头条等app的user_ ...
- python学习——正则表达项目
主要实现功能 从网页爬取关键信息,展示在自己写的界面上. 从http://www.5ppt.net/aricle.asp?id=3947&p=1,获取各个国家的疫情信息. 实现思路 使用req ...
- 学习正则有感by魔芋(命名问题)
魔芋: 事实上,我是反感一些特殊的名词.一些名词看上去就让人感觉到抗拒. 关于一个概念用不同的名词来定义,简直是太糟糕了. 举个例子: 匹配一个后面带有exp2的exp1的正则. 写法: exp1(? ...
- 学习正则前的预备 charCodeAt
charCodeAt 方法返回给定索引表示 UTF-16 代码单元(code unit)的 0 到 65535 的整数值. Unicode 与 UTF-16 字符串中字符的编码方式常见的有 Unico ...
- 怎么学习正则表达式?(正则的使用心得)
以前使用正则是不会自己去学或者去了解怎么实现正则的语法的,感觉好难懂的样子,于是拖到现在 其实正则不是我想象中的那么难,至少入门还是比较简单.我刚学习了一些比较简单的,谈谈我对正则的理解以及使用心得, ...
- NeurIPS 2019 少样本学习研究亮点全解析
作者:Angulia Chao 编辑:Joni Zhong 少样本学习(Few-Shot Learning)是近两年来非常有研究潜力的一个子方向,由于深度学习在各学科交叉研究与商业场景都有比较普遍的应 ...
- 60分钟正则从入门到深入
本文转载自网络.转载编辑过程中,可能有遗漏或错误,请以原文为准. 原文作者:水墨寒湘 原文链接:https://juejin.im/post/582dfc... 正则表达式对于我来说一直像黑暗魔法一样 ...
- 玩转正则之highlight高亮
程序员在编写代码的时候少不了和字符串以及"查询"打交道,两者的交集中有一个叫做正则表达式的的东西,这家伙用好了可以提高编程效率,用不好的话...你可以先去好好学一学. 关于正则的使 ...
最新文章
- 谷歌工程师:聊一聊深度学习的weight initialization
- 数组中只出现1次的2个数
- CentOS6.0 yum php mcrypt 扩展安装问题
- c语言运行程序没有,这个程序怎么运行?为什么显示没有exe??
- 如何在 Mac 上忘记 Wi-Fi 网络?
- [UML]UML系列——类图class的实现关系Realization
- 【MapGIS必备】常见问题处理(第十四期)
- PyQt5 UI设计时自动创建qrc文件
- 主动降噪技术matlab,主动降噪技术(ANC)的前生今世--原理仿真
- 马氏距离Mahalanobis Distance实例
- Android穿山甲SDK激励视频
- V2X消息之MAP消息解读
- 物联卡需要实名认证吗?物联网卡实名认证有什么用?
- ucmucsiacpi设备感叹号 冰刃4双屏无声音解决办法
- 李群,李代数的几何学心得总结
- Java集合(超详细-含源码)
- python 3.0 实现多级反馈队列进程调度算法
- 子曾经曰过,今天应该要振奋精神了。
- 出国不用兑换美元啦细说人民币跨境支付系统的幕后功臣
- Python 关键字global全局变量详解