C#正则表达式 筛选特殊字符串 欢迎高手!!
如下一段字符串,是从远程服务器取下来的,现在需要取得futures中的某一个值 如XXXX09 整一段字符串就是以下的内容了。。
如何使用正则去筛选?futures[]里面的数组可能会多会少,因为会随时更改, 所以用substring不现实 但都是这样的结构。
求高手!
string str="var js={futures:["CF3094,CF309,XXXX09,20450,20445,20450,20450,20420,10260,502,0,17990,16600,20425,0,0,26916,25,0.12%,20440,2,131,369,1,0,20445,20450,2013-07-02 11:19:09,1"],extendedFutures:["20450,97|20445,34","11:19:06,20450,2,1,0,2,1|11:17:06,20450,2,1,-2,1,0|11:12:06,20445,4,-1,0,5,-1|11:08:06,20445,8,1,8,0,0|11:05:06,20445,2,1,2,0,0|11:01:51,20450,2,1,0,2,1|11:01:21,20445,2,1,2,0,0|10:58:51,20445,2,1,0,2,1|10:58:01,20445,4,-1,2,3,1|10:56:01,20445,2,-1,0,5,-1|10:55:21,20445,2,-1,0,5,-1|10:54:51,20445,4,-1,-4,1,0|10:53:21,20445,2,-1,-2,1,0|10:51:16,20445,4,-1,-4,1,0|10:48:21,20445,4,-1,0,5,-1|10:44:31,20445,2,-1,0,5,-1|10:43:16,20445,2,-1,0,5,-1|10:42:46,20445,24,1,-6,4,-1|10:38:46,20440,2,-1,-2,1,0|10:15:01,20445,2,1,2,0,0|10:02:31,20445,2,1,2,0,0|09:56:46,20440,2,-1,0,5,-1|09:56:31,20440,6,-1,-6,1,0|09:48:56,20440,6,-1,-2,4,-1|09:48:46,20440,152,1,-144,4,-1"]}";
string str = "var js={futures:["CF3094,CF309,XXXX09,20450,20445,20450,20450,20420,10260,502,0,17990,16600,20425,0,0,26916,25,0.12%,20440,2,131,369,1,0,20445,20450,2013-07-02 11:19:09,1"],extendedFutures:["20450,97
[解决办法]
20445,34","11:19:06,20450,2,1,0,2,1
[解决办法]
11:17:06,20450,2,1,-2,1,0
[解决办法]
11:12:06,20445,4,-1,0,5,-1
[解决办法]
11:08:06,20445,8,1,8,0,0
[解决办法]
11:05:06,20445,2,1,2,0,0
[解决办法]
11:01:51,20450,2,1,0,2,1
[解决办法]
11:01:21,20445,2,1,2,0,0
[解决办法]
10:58:51,20445,2,1,0,2,1
------解决方案--------------------
10:58:01,20445,4,-1,2,3,1
[解决办法]
10:56:01,20445,2,-1,0,5,-1
[解决办法]
10:55:21,20445,2,-1,0,5,-1
[解决办法]
10:54:51,20445,4,-1,-4,1,0
[解决办法]
10:53:21,20445,2,-1,-2,1,0
[解决办法]
10:51:16,20445,4,-1,-4,1,0
[解决办法]
10:48:21,20445,4,-1,0,5,-1
[解决办法]
10:44:31,20445,2,-1,0,5,-1
[解决办法]
10:43:16,20445,2,-1,0,5,-1
[解决办法]
10:42:46,20445,24,1,-6,4,-1
[解决办法]
10:38:46,20440,2,-1,-2,1,0
[解决办法]
10:15:01,20445,2,1,2,0,0
[解决办法]
10:02:31,20445,2,1,2,0,0
[解决办法]
09:56:46,20440,2,-1,0,5,-1
[解决办法]
09:56:31,20440,6,-1,-6,1,0
[解决办法]
09:48:56,20440,6,-1,-2,4,-1
[解决办法]
09:48:46,20440,152,1,-144,4,-1"]}";
//修改一下的数字,分别得到对应的值
string v1 = Regex.Match(str, @"(?<=\{\s*?futures:\[['""]([^,,]+?,){0})[^,,]+").Value;//CF3094
string v2 = Regex.Match(str, @"(?<=\{\s*?futures:\[['""]([^,,]+?,){1})[^,,]+").Value;//CF309
string v3 = Regex.Match(str, @"(?<=\{\s*?futures:\[['""]([^,,]+?,){2})[^,,]+").Value;//XXXX09
string str = "var js={futures:["CF3094,CF309,XXXX09,20450,20445,20450,20450,20420,10260,502,0,17990,16600,20425,0,0,26916,25,0.12%,20440,2,131,369,1,0,20445,20450,2013-07-02 11:19:09,1"],extendedFutures:["20450,97
[解决办法]
20445,34","11:19:06,20450,2,1,0,2,1
[解决办法]
11:17:06,20450,2,1,-2,1,0
[解决办法]
11:12:06,20445,4,-1,0,5,-1
[解决办法]
11:08:06,20445,8,1,8,0,0
[解决办法]
11:05:06,20445,2,1,2,0,0
[解决办法]
11:01:51,20450,2,1,0,2,1
[解决办法]
11:01:21,20445,2,1,2,0,0
[解决办法]
10:58:51,20445,2,1,0,2,1
[解决办法]
10:58:01,20445,4,-1,2,3,1
[解决办法]
10:56:01,20445,2,-1,0,5,-1
[解决办法]
10:55:21,20445,2,-1,0,5,-1
[解决办法]
10:54:51,20445,4,-1,-4,1,0
[解决办法]
10:53:21,20445,2,-1,-2,1,0
[解决办法]
10:51:16,20445,4,-1,-4,1,0
[解决办法]
10:48:21,20445,4,-1,0,5,-1
[解决办法]
10:44:31,20445,2,-1,0,5,-1
[解决办法]
10:43:16,20445,2,-1,0,5,-1
[解决办法]
10:42:46,20445,24,1,-6,4,-1
[解决办法]
10:38:46,20440,2,-1,-2,1,0
[解决办法]
10:15:01,20445,2,1,2,0,0
[解决办法]
10:02:31,20445,2,1,2,0,0
[解决办法]
09:56:46,20440,2,-1,0,5,-1
[解决办法]
09:56:31,20440,6,-1,-6,1,0
[解决办法]
09:48:56,20440,6,-1,-2,4,-1
[解决办法]
09:48:46,20440,152,1,-144,4,-1"]}";
int index = 1;
string v1 = Regex.Match(str, @"(?is)(?<=\{\s*?futures:\["")[^""]+?(?=""\])").Value.Split(',')[index];