110,534
社区成员
发帖
与我相关
我的任务
分享
string a = "qweqw[as]dasdas[adc]11";
var r = Regex.Matches(a, @"\[(.+?)\]");
foreach(Match x in r) Console.WriteLine(x.Groups[1].Value);
string a = "qweqw[as]dasdas[adc]";
var b = a.Split(new char[] { '[', ']' });
Console.WriteLine(b[1]); //as
Console.WriteLine(b[3]); //adc
Module Module1
Sub Main()
Dim Re As System.Text.RegularExpressions.Regex
Re = New System.Text.RegularExpressions.Regex("(?<=\[)\w+(?=\])")
Dim Mc As System.Text.RegularExpressions.MatchCollection
Dim M
Mc = Re.Matches("qweqw[as]dasdas[adc]")
For Each M In Mc
Console.WriteLine(M)
Next
Console.ReadKey()
End Sub
End Module
string a = "qweqw[as]dasdas[adc]";
string[] b = a.Split(']');
StringBuilder sb = new StringBuilder();
foreach (var c in b)
{
if (c.IndexOf("[") > -1)
{
sb.Append(c.Substring(c.IndexOf("[") + 1) + " ");
}
}
Console.WriteLine(sb.ToString());
StringCollection resultList = new StringCollection();
try
{
Regex regexObj = new Regex(@"\[(?<result>[^\[\]]+)\]");
Match matchResult = regexObj.Match(@"qweqw[as]dasdas[adc]");
while (matchResult.Success)
{
resultList.Add(matchResult.Groups["result"].Value);
matchResult = matchResult.NextMatch();
}
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
StringCollection resultList = new StringCollection();
try {
Regex regexObj = new Regex(@"\[(?<result>)[^[\]]+\]");
Match matchResult = regexObj.Match(subjectString);
while (matchResult.Success) {
resultList.Add(matchResult.Groups[1].Value);
matchResult = matchResult.NextMatch();
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}