The basic regex is this:
var pattern = @"KeywordB:s*(w*)";
s* = any number of spaces
w* = 0 or more word characters (non-space, basically)
() = make a group, so you can extract the part that matched
var pattern = @"KeywordB:s*(w*)";
var test = @"KeywordB: TextToFind";
var match = Regex.Match(test, pattern);
if (match.Success) {
Console.Write("Value found = {0}", match.Groups[1]);
}
If you have more than one of these on a line, you can use this:
var test = @"KeywordB: TextToFind KeyWordF: MoreText";
var matches = Regex.Matches(test, @"(?:s*(?<key>w*):s?(?<value>w*))");
foreach (Match f in matches ) {
Console.WriteLine("Keyword '{0}' = '{1}'", f.Groups["key"], f.Groups["value"]);
}
Also, check out the regex designer here: http://www.radsoftware.com.au/. It is free, and I use it constantly. It works great to prototype expressions. You need to rearrange the UI for basic work, but after that it's easy.
(fyi) The "@" before strings means that no longer means something special, so you can type @"c:fun.txt" instead of "c:fun.txt"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…