我试图编写一个代码,以便在列表中获得匹配,但没有匹配标记,直到现在,我已经在WP7应用程序中构建了以下C#应用程序代码
public static MatchCollection MatchTags(string content, string string_start, string string_end)
{
MatchCollection matches = Regex.Matches(content, string_start + "(.*?)" + string_end, RegexOptions.IgnoreCase);
return matches;
}那么,在进行匹配提取之后,如何在不使用替换函数的情况下返回没有string_start、string_end (匹配标记)的匹配呢?
发布于 2013-11-22 18:26:10
当我得到下一段代码的结果时,它就能工作了:
string my_string_no_tags = matches[number].Groups[1].Value;发布于 2013-11-22 18:11:04
用围城..。
String.Format("(?<={0}).*?(?={1})",string_start,string_end);虽然你也可以使用Groups.也就是说在你的regex中,(.*?)会捕获第一组中的内容。
MatchTags(content,start,end).Cast<Match>()
.Select(x=>x.Groups[1].Value);发布于 2013-11-22 18:38:41
考虑以下代码..。
MatchCollection matches = Regex.Matches(content, string.Format("(?<={0}).*?(?={1})", string_start, string_end), RegexOptions.IgnoreCase);
return matches;祝好运!
https://stackoverflow.com/questions/20151581
复制相似问题