方法:
public List<string> ClassificationOfExtracting(string strs, string startStr, string endStr)
{
List<string> result = new List<string>();
string regex = "(?<=(" + startStr + "))[.\\s\\S]*?(?=(" + endStr + "))";
Regex rg = new Regex(regex);
if (string.IsNullOrEmpty(strs))
return null;
bool isMatch = Regex.IsMatch(strs, regex);
if (!isMatch)
return null;
MatchCollection matchCol = Regex.Matches(strs, regex);
if (matchCol.Count > 0)
{
for (int i = 0; i < matchCol.Count; i++)
{
result.Add(matchCol[i].Value);
}
}
return result;
}
调用时: 就可以获取E和F之间的诗句了
Poems = ClassificationOfExtracting(strs, "E", "F");
E咏柳 唐 贺知章 碧玉妆成一树高,万条垂下绿丝绦 不知细叶谁裁出,二月春风似剪刀F
|