以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  金字塔vba可以使用正则表达式吗?  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=75741)

--  作者:hou731017
--  发布时间:2015/2/19 10:04:13
--  金字塔vba可以使用正则表达式吗?
如题
--  作者:王锋
--  发布时间:2015/2/19 18:44:13
--  

金字塔VBA实际使用的是VBS语法,你用搜索引擎关键字 VBS 正则表达式 就可以搜到到相关信息了


--  作者:guotx2010
--  发布时间:2015/2/26 8:30:19
--  

可以的,下面的代码是读取网页内容,然后用正则表达式进行分析的:

 

    On Error Resume Next
    Set regEx = CreateObject("VBScript.RegExp")
    With CreateObject("WinHttp.WinHttpRequest.5.1")
        .Open "GET", "http://data.eastmoney.com/zjlx/detail.html", False
        .setRequestHeader "Connection", "Close"
        .setRequestHeader "Content-Type", "text/html; charset=gb2312"
        \'.setRequestHeader "User-Agent", "Mozilla/30.0"
        .Send
        respText = .responseText
    End With
   
    \'Debug.Print respText
   
    pattern = pattern = """\\d{6},.+?"""             \'   """" & "\\d{6}"
    \'pattern = "<a href=""http://quote.eastmoney.com/" & "\\w{2}" & "\\d{6}" & ".html"">" & "\\d{6}"
    \'<a href="http://quote.eastmoney.com/SZ002190.html">----测试OK
    With regEx
        .Global = True
        .pattern = pattern
    End With

    Set matchs = regEx.Execute(respText)