I've been wrestling with this for days. I'm trying to find a string between two markers in a text file. The markers are "Begin InputTables" and "Begin OutputColumns". The string I need to find is the text between double quotes, i.e. "PCODE" and "CLIENTSX" in:
I can get the regex to find the string if I move the string up to a point immediately after the look-behind...
"Begin InputTables PCODE"
... but of course that does me no good since what I have are hundreds of files where the string is in a line after "Begin InputTables".
I'm searching for the string in For... Each iterations, so I only need to find one at a time.
Here's the code:
For Each tableInQueryToFind In txtInputTablesInDir
If textIn.Peek <> -1 Then
Dim tableNm As String = tableInQueryToFind.Name
Dim findText As String = tableNm
Dim strLength As Integer = Len(findText)
findText = findText.Substring(0, strLength - 4)
Dim pattern As String = "(?<=^Begin InputTables$)" & findText & "\b" ' & "+(?<=End)??$"
Dim options As RegexOptions = RegexOptions.IgnoreCase Or RegexOptions.Multiline
Dim m As Match = Regex.Match(line, pattern, options)
If Not IsNothing(line) Then
If m.Success Then
My.Computer.FileSystem.WriteAllText(tableInQueriesOutputFullPath, "<query>" & queriesDirFileNm.Name & "</query>" & "<tableinquery>" & findText & "</tableinquery>" & vbNewLine, True)