如何匹配以某字符开始并以字符结束的字符串,
例如在字符串"aabb[cd,/ada]eesfdfas中找出"["和"]"中的字符串
8 个解决方案
#1
我看了两天了
还没有一点头绪,郁闷了
还没有一点头绪,郁闷了
#2
"\[.*\]"
#3
我瞎写的,都忘了:P
#4
Regex r = new Regex("\\[*\\]");
MatchCollection m = r.Matches("aaba\\[ba\\]bb");
#5
Match m = r.Match("aaba\\[b\\]bb");
#6
Regex r = new Regex("\\[");
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
Regex r = new Regex("\\]");
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
we can find the position of [ and ] from index
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
Regex r = new Regex("\\]");
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
we can find the position of [ and ] from index
#7
@"\[(?<content>[^]]*)\]"
#8
to lbx1979(Love Arsenal)/starky(爱在西元前):
thanks. it's right.
thanks. it's right.
#1
我看了两天了
还没有一点头绪,郁闷了
还没有一点头绪,郁闷了
#2
"\[.*\]"
#3
我瞎写的,都忘了:P
#4
Regex r = new Regex("\\[*\\]");
MatchCollection m = r.Matches("aaba\\[ba\\]bb");
#5
Match m = r.Match("aaba\\[b\\]bb");
#6
Regex r = new Regex("\\[");
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
Regex r = new Regex("\\]");
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
we can find the position of [ and ] from index
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
Regex r = new Regex("\\]");
Match m = r.Match("aaba\\[b\\]bb");
Console.WriteLine(m.Index);
Console.WriteLine(m.Length);
we can find the position of [ and ] from index
#7
@"\[(?<content>[^]]*)\]"
#8
to lbx1979(Love Arsenal)/starky(爱在西元前):
thanks. it's right.
thanks. it's right.