通过VB脚本正则表达式

时间:2014-08-26 05:17:37

标签: regex vbscript

我有文本文件。文件包含如下

文件:

hello:all\hareesh\ _is very bad boy

hello:all\sampath _good fellow

hello:all\hareesh\going to office very late

hello:all\Jithendra is hero

hello:all\hareesh\ _is going on vacation 

hello:all\hareesh\ _is worst fellow

hello:all\Suresh_india

hello:all\hareesh\ _jaffa

所以我想要的是打印线,如果包含hareesh_的行,那么忽略剩余的情况

所以我的输出应该是(注意:不要在单词之间插入空格

输出:

hello:all\hareesh\ _is very bad boy

hello:all\hareesh\ _is going on vacation 

hello:all\hareesh\ _is worst fellow

hello:all\hareesh\ _jaffa

我的代码是:

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

set objRegEx = CreateObject("VBScript.RegExp")

objRegEx.Global = True   

objRegEx.Pattern =".{0,}" &"\b" & "hareesh" & "[^;0-9a-zA-z-~\-_=+']" & ".{0,}\n"

objRegEx.Ignorecase = true


Set objFile = objFSO.OpenTextFile("C:\Users\Hareesh\Desktop\EPB\Hari.txt", ForReading)

strTargetText = objFile.ReadAll

objFile.Close

Set colMatches = objRegEx.Execute(strTargetText)   

If colMatches.Count > 0 Then

   For Each strMatch in colMatches  

       strText = strText & strMatch.Value 

   Next

End If

Wscript.Echo strText

请帮帮我

提前致谢

1 个答案:

答案 0 :(得分:0)

.*?hareesh\\?\s*_.*

Regular expression visualization

Debuggex Demo