回答編集履歴

2

デバッグ用のデータが混ざっていたので修正

2017/03/30 06:35

投稿

Zuishin
Zuishin

スコア28662

test CHANGED
@@ -162,7 +162,7 @@
162
162
 
163
163
  volume:1
164
164
 
165
- evaluation:evaluation
165
+ evaluation:
166
166
 
167
167
  total:
168
168
 

1

追記

2017/03/30 06:34

投稿

Zuishin
Zuishin

スコア28662

test CHANGED
@@ -31,3 +31,343 @@
31
31
 
32
32
 
33
33
  現在与えられたデータを解析する仕様は満たしていますが、これでいいのですか?
34
+
35
+
36
+
37
+ 参考までにデータはこうなります。
38
+
39
+
40
+
41
+ ```C#
42
+
43
+ var cls = @"<td\s+rowspan=""(?<classLength>\d+)"">(?<class>[^<]+)</td>\s*";
44
+
45
+ var country = @"<td\s+rowspan=""(?<countryLength>\d+)"">(?<country>[^<]+)</td>\s*" + cls;
46
+
47
+ var header =string.Format(@"(?:{0}|{1}|\s*)", country, cls);
48
+
49
+ var dateTime = @"<td>\s*<div>(?<date>[^<]*)</div>\s*<div>(?<time>[^<]*)</div>\s*</td>\s*";
50
+
51
+ var no = @"<td>(?<no>[^<]*)</td>\s*";
52
+
53
+ var value = @"<td>(?<value>[^<]*)</td>\s*";
54
+
55
+ var volume = @"<td>\s*<div>(?<volume>[^<]*)</div>\s*<div></div>\s*</td>\s*";
56
+
57
+ var evaluation = @"<td><div>(?<evaluation>[^<]*)</div></td>\s*";
58
+
59
+ var total = @"<td><div>(?<total>[^<]*)</div></td>\s*";
60
+
61
+ var b = @"<td>(?<b>[^<]*)</td>\s*";
62
+
63
+ var regex = new Regex(header + dateTime + no + value + volume + evaluation + total + b, RegexOptions.Multiline);
64
+
65
+ var items = regex
66
+
67
+ .Matches(src)
68
+
69
+ .OfType<Match>()
70
+
71
+ .Select(a => new
72
+
73
+ {
74
+
75
+ country = a.Groups["country"].Value,
76
+
77
+ countryLength = a.Groups["countryLength"].Value,
78
+
79
+ cls = a.Groups["class"].Value,
80
+
81
+ classLength = a.Groups["classLength"].Value,
82
+
83
+ date = a.Groups["date"].Value,
84
+
85
+ time = a.Groups["time"].Value,
86
+
87
+ no = a.Groups["no"].Value,
88
+
89
+ value = a.Groups["value"].Value,
90
+
91
+ volume = a.Groups["volume"].Value,
92
+
93
+ evaluation = a.Groups["evaluation"].Value,
94
+
95
+ total = a.Groups["total"].Value,
96
+
97
+ b = a.Groups["b"].Value
98
+
99
+ });
100
+
101
+ foreach (var item in items)
102
+
103
+ {
104
+
105
+ Console.WriteLine(string.Format(
106
+
107
+ "country:{8}\ncountryLength:{9}\nclass:{10}\nclassLength:{11}\ndate:{0}\ntime:{1}\nno:{2}\nvalue:{3}\nvolume:{4}\nevaluation:{5}\ntotal:{6}\nb:{7}\n\n",
108
+
109
+ item.date,
110
+
111
+ item.time,
112
+
113
+ item.no,
114
+
115
+ item.value,
116
+
117
+ item.volume,
118
+
119
+ item.evaluation,
120
+
121
+ item.total,
122
+
123
+ item.b,
124
+
125
+ item.country,
126
+
127
+ item.countryLength,
128
+
129
+ item.cls,
130
+
131
+ item.classLength
132
+
133
+ ));
134
+
135
+ }
136
+
137
+ ```
138
+
139
+
140
+
141
+ 出力
142
+
143
+
144
+
145
+ ```
146
+
147
+ country:JAPAN
148
+
149
+ countryLength:4
150
+
151
+ class:class1
152
+
153
+ classLength:2
154
+
155
+ date:2017/03/29
156
+
157
+ time:15:36:12
158
+
159
+ no:10011879
160
+
161
+ value:18.5121
162
+
163
+ volume:1
164
+
165
+ evaluation:evaluation
166
+
167
+ total:
168
+
169
+ b:a
170
+
171
+
172
+
173
+
174
+
175
+ country:
176
+
177
+ countryLength:
178
+
179
+ class:
180
+
181
+ classLength:
182
+
183
+ date:2017/03/30
184
+
185
+ time:01:16:01
186
+
187
+ no:1092115019
188
+
189
+ value:18.5237
190
+
191
+ volume:1
192
+
193
+ evaluation:
194
+
195
+ total:
196
+
197
+ b:c
198
+
199
+
200
+
201
+
202
+
203
+ country:
204
+
205
+ countryLength:
206
+
207
+ class:class2
208
+
209
+ classLength:2
210
+
211
+ date:2017/03/29
212
+
213
+ time:15:36:24
214
+
215
+ no:100001894
216
+
217
+ value:18.5028
218
+
219
+ volume:1
220
+
221
+ evaluation:
222
+
223
+ total:
224
+
225
+ b:a
226
+
227
+
228
+
229
+
230
+
231
+ country:
232
+
233
+ countryLength:
234
+
235
+ class:
236
+
237
+ classLength:
238
+
239
+ date:2017/03/30
240
+
241
+ time:01:15:53
242
+
243
+ no:2115002
244
+
245
+ value:18.5136
246
+
247
+ volume:1
248
+
249
+ evaluation:
250
+
251
+ total:
252
+
253
+ b:b
254
+
255
+
256
+
257
+
258
+
259
+ country:HONGKONG
260
+
261
+ countryLength:4
262
+
263
+ class:class1
264
+
265
+ classLength:2
266
+
267
+ date:2017/03/30
268
+
269
+ time:01:15:47
270
+
271
+ no:1014990
272
+
273
+ value:17.3090
274
+
275
+ volume:1
276
+
277
+ evaluation:
278
+
279
+ total:
280
+
281
+ b:a
282
+
283
+
284
+
285
+
286
+
287
+ country:
288
+
289
+ countryLength:
290
+
291
+ class:
292
+
293
+ classLength:
294
+
295
+ date:2017/03/29
296
+
297
+ time:15:36:38
298
+
299
+ no:1020
300
+
301
+ value:17.3270
302
+
303
+ volume:1
304
+
305
+ evaluation:
306
+
307
+ total:
308
+
309
+ b:b
310
+
311
+
312
+
313
+
314
+
315
+ country:
316
+
317
+ countryLength:
318
+
319
+ class:class2
320
+
321
+ classLength:2
322
+
323
+ date:2017/03/30
324
+
325
+ time:01:15:35
326
+
327
+ no:14980
328
+
329
+ value:17.2909
330
+
331
+ volume:1
332
+
333
+ evaluation:
334
+
335
+ total:
336
+
337
+ b:a
338
+
339
+
340
+
341
+
342
+
343
+ country:
344
+
345
+ countryLength:
346
+
347
+ class:
348
+
349
+ classLength:
350
+
351
+ date:2017/03/29
352
+
353
+ time:15:36:47
354
+
355
+ no:1031
356
+
357
+ value:17.3083
358
+
359
+ volume:1
360
+
361
+ evaluation:
362
+
363
+ total:
364
+
365
+ b:b
366
+
367
+ ```
368
+
369
+
370
+
371
+
372
+
373
+