感谢您添加的规格。这应该有效:
^ # Start of line
(IDD_\w+) # Alphanumeric identifier, starting with IDD_
\s+DIALOG\b # followed by "DIALOG"
((?:(?!^END\b).)*) # and any number of characters unless there's an END in-between
IDD_whatever
这将匹配从直到下一个的整个部分END
。然后您需要获取该字符串并将以下正则表达式应用于它:
"([^"]*&[^"]*)" # String containing at least one &
这是一个 C# 示例:
Regex sectionRegex = new Regex(
@"^ # Start of line
(IDD_\w+) # Alphanumeric identifier, starting with IDD_
\s+DIALOG\b # followed by ""DIALOG""
((?:(?!^END\b).)*) # and any number of characters unless there's an END in-between",
RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
Regex altCRegex = new Regex(
@"""([^""]*&[^""]*)"" # String containing at least one &",
RegexOptions.IgnorePatternWhitespace);
Match matchResults = sectionRegex.Match(subjectString);
while (matchResults.Success) {
identifier = matchResults.Groups[1].Value;
section = matchResults.Groups[2].Value;
Match sectionResults = altCRegex.Match(section);
while (sectionResults.Success) {
altCString = sectionResult.Groups[1].Value;
sectionResults = sectionResults.NextMatch();
}
matchResults = matchResults.NextMatch();
}
identifier
当然,这个代码片段对and没有任何作用altCString
,但我想你明白了。