如果我理解这个问题......
public static String GetTextBetween(String source, String leftWord, String rightWord)
{
return
Regex.Match(source, String.Format(@"{0}\s(?<words>[\w\s]+)\s{1}", leftWord, rightWord),
RegexOptions.IgnoreCase).Groups["words"].Value;
}
Run Code Online (Sandbox Code Playgroud)
使用:
Console.WriteLine(GetTextBetween("Hello good day", "hello", "day"));
Run Code Online (Sandbox Code Playgroud)
在msdn上阅读它:正则表达式