[英]Match with reges excluding string tags
我正在尝试编写代码以获取列表中的匹配项,但没有匹配项标记,直到现在我已经在用C#编写的WP7应用程序中构建了以下代码
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;
}
那么如何在匹配提取后不使用replace函数的情况下不使用string_start,string_end(匹配标签)返回匹配?
使用环顾四周。
String.Format("(?<={0}).*?(?={1})",string_start,string_end);
尽管您也可以使用groups.ie,但在正则表达式(.*?)
中将捕获组1中的内容。然后不需要环顾四周。
MatchTags(content,start,end).Cast<Match>()
.Select(x=>x.Groups[1].Value);
当我得到下一个代码的结果时,它起作用:
string my_string_no_tags = matches[number].Groups[1].Value;
考虑以下代码...
MatchCollection matches = Regex.Matches(content, string.Format("(?<={0}).*?(?={1})", string_start, string_end), RegexOptions.IgnoreCase);
return matches;
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.