var str="Public WithEvents treCustomType As AxMSComctlLib.AxTreeView"
alert(str.match(/treCustomType/))

解决方案 »

  1.   

    谢谢你,我想要的不是程序使用的。就是想要一个正则表达式
    如:Public WithEvents treCustomType Is AxMSComctlLib.AxTreeView
    我想找出类型被定义为AxMSComctlLib.AxTreeView的一个名称也就是treCustomType 
    这个名称不是固定的。前面的Public WithEvents是不变的。谢谢。
      

  2.   

    <script language=javascript>
    var str="Public WithEvents treCustomType As AxMSComctlLib.AxTreeView"
    var re=/Public\s+WithEvents\s+(.+?)\s/
    re.test(str)
    alert(RegExp.$1)
    </script>
      

  3.   

    对不起,我没有说清楚,重新说吧。
    一段文本:
    Public WithEvents _cmdSearch_2 As System.Windows.Forms.Button
    Public WithEvents _chkULCase_1 As System.Windows.Forms.CheckBox
    Public WithEvents sstabSearch As System.Windows.Forms.TabControl
    Public WithEvents staMain As AxComctlLib.AxStatusBar
    Public WithEvents treGroup As AxMSComctlLib.AxTreeView
            Public WithEvents treTree As AxMSComctlLib.AxTreeView
    Public WithEvents ImgToolBar As AxMSComctlLib.AxImageList
    Public WithEvents rtfFile As AxRichTextLib.AxRichTextBox
    比如说上面这段文本
    我想要查出其中的treGroup ,treTree 。
    我写了一个正则表达式:(?<Name>\b\w+\b)\s+As\s+(AxmscomctlLib.AxTreeView)
    查出来的是:
    treGroup As AxMSComctlLib.AxTreeView
    treTree As AxMSComctlLib.AxTreeView
    刚学不是很会写,想问下就是一个表达式语句。不是在程序中通过一些方法调用的
    就是直接查。谢谢了啊
      

  4.   

    <textarea id="textarea1">
    Public WithEvents _cmdSearch_2 As System.Windows.Forms.Button
    Public WithEvents _chkULCase_1 As System.Windows.Forms.CheckBox
    Public WithEvents sstabSearch As System.Windows.Forms.TabControl
    Public WithEvents staMain As AxComctlLib.AxStatusBar
    Public WithEvents treGroup As AxMSComctlLib.AxTreeView
        Public WithEvents treTree As AxMSComctlLib.AxTreeView
    Public WithEvents ImgToolBar As AxMSComctlLib.AxImageList
    Public WithEvents rtfFile As AxRichTextLib.AxRichTextBox</textarea>
    <script language=javascript>
    function getName(key)
    {
    var str=document.getElementById("textarea1").value
    var re=new RegExp("Public\\s+WithEvents\\s+(.+?)\\s+As(.+?)"+key,"i")
    while(re.test(str))
    {
    alert(RegExp.$1)
    str=str.replace(re,"")
    }
    }
    getName("TreeView")
    </script>