C# 正则表达式 将找到的字符串存到字符串数组

string[] ID = System.Text.RegularExpressions.Regex.Matches(strLine, @"(?<=@ID:)\S+");
。。。在strline找到所有满足@"(?<=@ID:)\S+,存到一个字符串数组中

Pattern p = Pattern.compile("[0-9]{7,8}");
String str = "11223333 2233311 22231233";
Matcher m = p.matcher(str);
//由于不知道有多少个电话号码会被匹配出来,所以采用List存放电话号码
List<String> mobileList = new ArrayList<String>();
while(m.find()){
mobileList.add(m.group()); //将匹配出的电话号码存放到mobileList中
}
String[] mobiles = new String[mobileList.size()]; //声明数组存放电话号码
int i = 0;
for(String mobile : mobileList){ //将list中的电话号码转存到数组中
mobiles[i] = mobile;
i++;
}
for(int j=0;j<mobiles.length;j++){
System.out.println(mobiles[j]); //打印电话号码
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-11-28
static void Main(string[] args)
{
Regex reg = new Regex(@"url\((['""]?)(.+[^'""])\1\)"); //注意里面的引号 要用双引号表示,而不是用反斜杠
Console.WriteLine(reg.Match(@"{background-image:url(//ssl.gstatic.com/ui/v1/menu/checkmark.png);backgro")); //输出 url(//ssl.gstatic.com/ui/v1/menu/checkmark.png)

Console.ReadKey();
}
第2个回答  推荐于2016-04-25
Matches mts=System.Text.RegularExpressions.Regex.Matches(strLine, @"(?<=@ID:)\S+");
你再转到string[] ID
id[0]=mts[0].groups[0].value 大概是这样的本回答被提问者采纳
相似回答