Search this forum for examples of Regular Expressions then post back here with your code if you have problems.
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
I read a few posts discussing Regular Expressions, in all cases it was searching for filenames with wild cards and I do not understand how to apply it.
Can someone tell me how I would insert a regular expression to solve this issue?
Const ForReading = 1
Const ForWriting = 2
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files|*.Txt"
intResult = objDialog.ShowOpen
If intResult = 0 Then
Wscript.Quit
Else
strFileName = objDialog.FileName
wscript.echo strFileName
End If
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading, True)
Set objFilew = objFSO.OpenTextFile("c:\outputfile.txt", ForWriting, True)
Do Until objFile.AtEndOfStream
strCurrentLine = objFile.ReadLine
if InStr(226, strCurrentLine, "3**40**", vbTextCompare) = 226 Then
this is off the cuff, but something like (you may need to play around with the pattern):
Const ForReading = 1
Const ForWriting = 2
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files|*.Txt"
intResult = objDialog.ShowOpen
If intResult = 0 Then
Wscript.Quit
Else
strFileName = objDialog.FileName
wscript.echo strFileName
End If
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading, True)
Set objFilew = objFSO.OpenTextFile("c:\outputfile.txt", ForWriting, True)
[red]Set oRE = New RegExp
oRE.Pattern = ".{225}3.*40.*"[/red]
Do Until objFile.AtEndOfStream
strCurrentLine = objFile.ReadLine
if [red]oRE.Test(strCurrentLine)[/red] Then
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
Wow, I dont understand that code at all but it seems to work!! The only thing I need it to do now is insert the text over the old text instead of indenting and pushing it over.
Thank you so much! I wonder if you happen to know how I can change it to insert the text and overwrite?
so you need to insert some text starting 3 characters from the end?
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
So you want to replace the matched text with something else?
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.