string pattern = "1+";
string input = "1+121";
Regex regex = new Regex(pattern);
MatchCollection matchCollection = regex.Matches(input);
foreach (Match item in matchCollection)
{
Console.WriteLine(item.Value);
}
Console.WriteLine();
pattern = "1\n";//
input = "1\n+121";
regex = new Regex(pattern);
matchCollection = regex.Matches(input);
foreach (Match item in matchCollection)
{
Console.WriteLine(item.Value);
}
Console.WriteLine();
pattern = @"1\+";//这里如果不加@会报错,加了@作为模式使用时并不是取消转义的作用,因为如果是取消转义,则认为是\+,但是其实是+
input = "1+121";
regex = new Regex(pattern);
matchCollection = regex.Matches(input);
foreach (Match item in matchCollection)
{
Console.WriteLine(item.Value);
}
输出:
1
1
1
1
1+