vb6正则表达式

yihuaheren008 2010-07-22 11:22:23
VB6的正则表达式怎么用?
我想写个方法校验两个txtbox,一个校验是否为数字,另一个校验是否为金额
...全文
83 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaboyzyq 2010-07-22
  • 打赏
  • 举报
回复
数字与金额有什么区别?
赵4老师 2010-07-22
  • 打赏
  • 举报
回复
用控件
msscript.ocx


cardname = RegExpN("<cardname>(.*)</cardname>", acks(idl), 1.1)'使用
Function RegExpN(ptn, txt, n) As String
'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 1) + "]"
'[22220101]
'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 2) + "]"
'[11000011]
'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 3) + "]"
'[00111100]
'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 4) + "]"
'[10101010]
'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 5) + "]"
'[]
'Debug.Print "[" + RegExpN("[a-z]+(\d+)[_.]", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 4) + "]"
'[xor10101010.]
'Debug.Print "[" + RegExpN("[a-z]+(\d+)[_.]", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 4.1) + "]"
'[10101010]
'Debug.Print "[" + RegExpN("<abc>(.*)</abc>", "<html><ab>AB</ab><abc>ABC汉字</abc></html>", 1) + "]"
'[<abc>ABC汉字</abc>]
'Debug.Print "[" + RegExpN("<abc>(.*)</abc>", "<html><ab>AB</ab><abc>ABC汉字</abc></html>", 1.1) + "]"
'[ABC汉字]
Dim rtnstr As String
Dim codestr As String
rtnstr = ""
With ScriptControl1
' Set script language (VBScript is the default).
.Language = "VBScript"
' Set UI interaction (TRUE is the default).
.AllowUI = True
' Copy the script to the control.
'--------------------------------------------------------
codestr = ""
codestr = codestr + "Function RegExpTest(patrn, strng, ns) " + vbCrLf
codestr = codestr + " Dim regEx, Match, Matches, RetStr, ii " + vbCrLf
codestr = codestr + " Dim nn,ss " + vbCrLf
codestr = codestr + " nn=fix(ns) " + vbCrLf
codestr = codestr + " if nn=ns then " + vbCrLf
codestr = codestr + " ss=-1 " + vbCrLf
codestr = codestr + " else " + vbCrLf
codestr = codestr + " ss=(ns-nn)*10-1 " + vbCrLf
codestr = codestr + " end if " + vbCrLf
codestr = codestr + " Set regEx = New RegExp " + vbCrLf
codestr = codestr + " regEx.Pattern = patrn " + vbCrLf
codestr = codestr + " regEx.IgnoreCase = True " + vbCrLf
codestr = codestr + " regEx.Global = True " + vbCrLf
codestr = codestr + " Set Matches = regEx.Execute(strng) " + vbCrLf
codestr = codestr + " ii=0 " + vbCrLf
codestr = codestr + " For Each Match in Matches " + vbCrLf
codestr = codestr + " ii=ii+1 " + vbCrLf
codestr = codestr + " if ii=nn then " + vbCrLf
codestr = codestr + " if ss=-1 then " + vbCrLf
codestr = codestr + " RetStr=Match.Value " + vbCrLf
codestr = codestr + " else " + vbCrLf
codestr = codestr + " RetStr=Match.SubMatches(ss)" + vbCrLf
codestr = codestr + " end if " + vbCrLf
codestr = codestr + " exit for " + vbCrLf
codestr = codestr + " end if " + vbCrLf
codestr = codestr + " Next " + vbCrLf
codestr = codestr + " RegExpTest = RetStr " + vbCrLf
codestr = codestr + " Set regEx = Nothing " + vbCrLf
codestr = codestr + "End Function " + vbCrLf
'--------------------------------------------------------
.AddCode codestr
Dim oMod As Object
Set oMod = .Modules(GlobalModule)
rtnstr = oMod.Run("RegExpTest", ptn, txt, n)
Set oMod = Nothing
End With
RegExpN = rtnstr
End Function

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧