110,561
社区成员
发帖
与我相关
我的任务
分享
(?is)
这个就是干那个用的,单行模式。满足要求的
string str = @"123-1234567890 098-0987654321 void";
Regex reg = new Regex(@"(?i)(?(?=\d{3}-\d{10}.{0,16}void)|\d{3}-\d{10})");
MatchCollection matches = reg.Matches(str);
for (int i = matches.Count - 1; i >= 0; i--)
{
if (matches[i].Value != "")
{
Console.WriteLine(matches[i].Value);
break;
}
}
string result = Regex.Match(yourStr,@"(?is)\d{3}-\d{10}(?=(((?!void).){20}|((?!void).){0,19}$))",RegexOptions.RightToLeft).Value;
string str = @"123-1234567890 098-0987654321 void";
Regex reg = new Regex(@"(?(?=\d{3}-\d{10}.{0,16}void)|\d{3}-\d{10})");
MatchCollection matches = reg.Matches(str);
if (matches.Count == 0 || matches[matches.Count - 1].Value == "")
Console.WriteLine("No Match");
else
Console.WriteLine(matches[matches.Count - 1].Value);
string result = Regex.Match(yourStr,@"(?is)\d{3}-\d{10}(?=(((?!void).){20}|((?!void).){0,19}$)((?!\d{3}-\d{10}).)*$)").Value;
//void我是小写的,如果你一定要大写,这样
string result = Regex.Match(yourStr,@"(?s)\d{3}-\d{10}(?=((?!VOID).){0,20}((?!\d{3}-\d{10}).)*$)").Value;
//如果你不限制大小写
string result = Regex.Match(yourStr,@"(?is)\d{3}-\d{10}(?=((?!void).){0,20}((?!\d{3}-\d{10}).)*$)").Value;
string result = Regex.Match(yourStr,@"(?s)\d{3}-\d{10}(?=((?!void).){0,20}((?!\d{3}-\d{10}).)*$)").Value;