JonXL
Well-known Member
- Joined
- Feb 5, 2018
- Messages
- 513
- Office Version
- 365
- 2016
- Platform
- Windows
Hello,
I have written up a series of procedures that look in each of all the text files within a given directory to find if any of the files contain a particular pattern of text.
The process I have works just fine. Where I am having issues is with finding my string within the text file. What I want to find is "PUSH:" followed by zero or any number of characters then either "Q" or "C" and again followed by any number of characters. I want it to do this without searching across new lines (in the text file those are CRLF). The code I have now for the comparison doesn't work because on lines after "PUSH:" in the file there are words with "Q" and/or "C" and these are being picked up as a match (
That would match, for example:
... when I really only want it to match things like these:
And not these:
Maybe I need a RegEx? Not really sure. I can loop through the text files one line at a time in which case the code I have above would work fine, but that would be slower so I am trying to do the search on the entire contents of the file in one go.
Any help is appreciated.
Thank you!
Jon
I have written up a series of procedures that look in each of all the text files within a given directory to find if any of the files contain a particular pattern of text.
The process I have works just fine. Where I am having issues is with finding my string within the text file. What I want to find is "PUSH:" followed by zero or any number of characters then either "Q" or "C" and again followed by any number of characters. I want it to do this without searching across new lines (in the text file those are CRLF). The code I have now for the comparison doesn't work because on lines after "PUSH:" in the file there are words with "Q" and/or "C" and these are being picked up as a match (
strTextFile
represents the entire text of a particular text file):
VBA Code:
If strTextFile Like "*PUSH*[QC]*" Then
That would match, for example:
Code:
BLAH BLAH PUSH: UJ
CONTINUE LINE
... when I really only want it to match things like these:
Code:
BLAH BLAH PUSH: JCO
CONTINUE LINE
Code:
BLAH BLAH PUSH: Q
CONTINUE LINE
Code:
BLAH BLAH PUSH: IOCQ PULL: OP
CONTINUE LINE
And not these:
Code:
BLAH BLAH PUSH: JP
CONTINUE LINE
Code:
BLAH BLAH PUSH: UI
QUIT
Maybe I need a RegEx? Not really sure. I can loop through the text files one line at a time in which case the code I have above would work fine, but that would be slower so I am trying to do the search on the entire contents of the file in one go.
Any help is appreciated.
Thank you!
Jon