1
我正在嘗試使用New關鍵字找到單詞。以下是我的代碼。查找單詞開始於正則表達式中的特定單詞
string contents = " holla holla testing is for NewFinancial History:\"xyz\" dsd NewFinancial History:\"abc\" New Investment History:\"abc\" dsds ";
var keys = Regex.Matches(contents, @"New(.+?):", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace).OfType<Match>().Select(m => m.Groups[0].Value.Trim().Replace(":", "")).Distinct().ToArray();
在上面的代碼中,它同時搜索NewFinancial History:\「xyz \」和New Investment History:\「abc \」。 它應該只能找到NewFinancial History:\「xyz \」而不是New Investment History:\「abc \」。 我想在New關鍵字之後找到沒有空格的單詞。上面的代碼使用和不使用空格來搜索。
(?<= New)(\ S +)。* ?: – Aferrercrafter