Hi @Latif fair point, sorry for jumping at the loop, now that you explained the varResult debug approach it makes sense
so the actual problem is simpler than it looks, its the patterns, not Multiline.
^(.) and (^.?)\s+(.*) are generic, they match any line, and matches(0) always returns the first match found in the whole text, wich is always line 1 of your file, Multiline on or off doesnt change wich match comes first. And your 3rd and 4th patterns require a colon in the line, without Multiline the ^ can only match the very start of the file, so those two blocks match nothing at all and varResult just keeps the value from the previous block. Both effects together look exactly like “same line repeating whatever expression i use”
the fix is putting the unique label of each field inside the pattern, then matches(0) lands on the right line by itself. I tested these against your PaperScanData.txt, all of them read with varMatches(0).Groups(1).ToString.Trim like you’re already doing
doc ref: (?m)^(AP.+?)\s{2,}\d{4}-\d{2}-\d{2} (Jarryds one, works fine)
recipient: (?m)^Recipient.\r?\n[ \t]+(.+)$ (the Trim matters here, the name line has trailing spaces)
pension incl UFP: Pension incl. UFP supplement\s+([\d.,]+)
pension year: Pension Year\s:\s*([^\r\n]+)
pay term: Pay term\s*:\s*(\d+)
date: Date\s*:\s*([\d.]+)
marital pension: Evt. opsat marital pension\s+([\d.,]+)
child pension: Evt. 10% opsat child pension\s+([\d.,]+)
easiest way to test without debug runs, paste your txt into regex101.com, set the flavor to .NET on the left, and try each pattern there, you see instantly what the group captures before touching studio
one heads up for later, your file has 2 letters separated by that long dashed line, and regex over the whole text always returns the first letters values. When you get to the multi record part, split the text on the dashed line first and run these patterns per chunk, one chunk = one letter = one db row. For testing on letter 1 right now you’re fine as is
and for the word document, since it must look identical to the txt you dont even need the extracted fields for that part, just write the raw file text into the doc using a monospaced font like Courier New and the column layout survives exactly. The regex fields then only feed your database
try them and post back if any field comes out wrong, i have your sample here so its quick to adjust. and if im still off on what you’re building, just correct me or share a bit more detail on the end goal, rather get corrected twice than answer the wrong problem again
hope this unblocks you