私はこの正規表現を持っています:
(?'box_id'\d{1,19})","box_name":"(?'box_name'[\w\d\.\s]{1,19})
ボックス名にスペースが含まれている場合を除いて、これはうまく機能します。たとえば、それを実行すると、スペースなしmy box
でが返されます。mybox
box_name
グループにスペースを含めるにはどうすればよいですか?
コード:
Regex reg = new Regex(@"""object_id"":""(?<object_id>\d{1,19})"",""file_name"":""(?<file_name>[\w.]+(?:\s[\w.]+)*)""");
MatchCollection matches = reg.Matches(result);
if ( matches == null) throw new Exception("There was an error while parsing data.");
if ( matches.Count > 0 )
{
FileArchive.FilesDataTable filesdataTable = new FileArchive.FilesDataTable();
foreach ( Match match in matches )
{
FileArchive.FilesRow row = filesdataTable.NewFilesRow();
row.ID = match.Groups["object_id"].Value;
row.Name = match.Groups["file_name"].Value;
}
}
入力:
{"objects":[{"object_id": "135248"、 "file_name": "some space here.jpg"、 "video_status": "0"、 "thumbnail_status": "1"}、{"object_id": " 135257 "、" file_name ":" jup 13.jpg "、" video_status ":" 0 "、" thumbnail_status ":" 1 "}、{" object_id ":" 135260 "、" file_name ":" my pic.jpg " 、"video_status": "0"、 "thumbnail_status": "1"}、{"object_id": "135262"、 "file_name": "EveningWav)es、Hon(olulu、Hawaii.jpg"、 "video_status": " 0 "、" thumbnail_status ":" 1 "}、{" object_id ":" 135280 "、" file_name ":" test with space.jpg "、" video_status ":"0"、 "thumbnail_status": "1"}]、 "status": "ok"}