For starters, k is not a "word" it's a regex
Match
class instance, so to get the content it matched, you need to use
k.Value
, not
k
Second, you are trying to write the list inside the loop that builds it - you want that at the end.
Thirdly, you have a StringBuilder and you don't even use it!
This looks like you are just guessing, and hoping it will all work - and that isn;t a strategy that will work, not at all. Stop guess, and start thinking - plan what you are going to do, and then if you don't know how, start breaking that down into smaller steps.
Try this:
string text = System.IO.File.ReadAllText(@"Dat is my file location");
Regex pattern1 = new Regex("(?<=ECU_ADDRESS).*?(?=)", RegexOptions.RightToLeft);
MatchCollection allMatches = pattern1.Matches(text);
StringBuilder words = new StringBuilder();
foreach (Match match in allMatches)
{
words.AppendLine(match.Value);
}
Console.Write(words.ToString());
But ... your regex looks wrong. It looks like the one I gave you yesterday, but hacked my somebody who doesn't understand regexes:
(?<=ID Config:\\s+)\\w+(?=\\s)
Your version doesn't have a terminating condition (the "(?=\\s)" in mine is a "stop at the first whitespace", yours is just empty, and the ".*?" part says "match absolutely nothing" because "*" means "zero or more repetitions of anything at all", and the "?" after it says "as few as possible" which will always means "none, please".
Stop, look at your data, and work out what exactly identifies the start and end of the text you want to capture. Then use the sample I gave you yesterday and a copy of Expresso to work out what you need:
Expresso[
^] - it's free, and it examines and generates Regular expressions.