我正在尝试对“NNTSY”进行正则表达式搜索,以便获得两个匹配项。
- NNTS
- NTSY
当我尝试使用 pattern 进行匹配?<NGrlyosylation>N[^P][ST][^P])"
时,我只得到一个匹配项,即NNTS
.
如何使用 Regex 进行匹配NNTSY
,以便找到两个匹配项?
注意:背景信息:可以在这里找到 Rosalind 问题。
这是我的代码。
input = "NNTSY";
Regex regex = new Regex("(?<NGrlyosylation>N[^P][ST][^P])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(input);
foreach (Match match in matches)
{
// Need to add 1 to because match index is 0 based
const int offset = 1;
yield return match.Index + offset;
}