一个txt文件要找出文本行以we字母开头的行文本并取整行文本,这个正则表达式如何写

解决方案 »

  1.   

    一行一行读入str
    if left(str,2) = "we" then
    str就是你要要的。
      

  2.   

    用二进制方式读取,一般来说换行是char(13) & char(10),然后又要以we开头,也就是查找十六进制0x0A0D7765,思路大概是这样。
      

  3.   

    正则 reg.Pattern = "we.*?" & vbCrLf
      

  4.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim s, b As Strings = "weWWWWWWWWWWWWWWWWWW1 " & vbCrLf & _
    "WWWWWWweWWWWWWWWWWWW " & vbCrLf & _
    "weWWWWWWWWWWWWWWWWWW2 " & vbCrLf & _
    "WWWWWWWWWWWWWWWWWWwe " & vbCrLfDim re As New RegExp  '要引用Microsoft VbScript  Regular expressions 5.5
    Dim sh, h As Objectre.Global = True
    re.MultiLine = Truere.Pattern = "^we.*"
    Set sh = re.Execute(s)b = ""
    For Each h In sh
        b = b & h
    Next h
    End Sub
      

  5.   

    Text1输入待处理字符Private Sub Command1_Click()
    Dim reg As Object
    Dim matchs As Object, match As Object
    Dim strData, s As StringstrData = Form1.Text1.Text
    Set reg = CreateObject("vbscript.regexp")
    reg.Global = True
    reg.IgnoreCase = True
    reg.Pattern = "we.*"Set matchs = reg.Execute(strData)For Each match In matchs
        s = s & match
    Next
    MsgBox s
    End Sub
      

  6.   

    用PilotEdit,这样写正则表达式:
    ^we*$
    查找所有行即可。
      

  7.   

    楼主要返回的是整行而非we后面部分,所以正确答案应该是^we.*$
      

  8.   

    正則表達式匹配沒有left/mid效率高.
    再說了15MB的文本,小的很.