在两个单词之间获取文字

Jam*_*mie 2 c# text

我需要知道如何在两个给定的单词之间得到单词.遗憾的是我不知道该怎么做.例如:大家好.

我该怎么做?

xtm*_*tmq 8

如果我理解这个问题......

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上阅读它:正则表达式