I have this json file. Part of it is given below :
{ "has_more" : false,
"items" : [ { "aliases" : [ "http://www.stackoverflow.com" ],
"api_site_parameter" : "stackoverflow",
"markdown_extensions" : [ "Prettify" ],
"name" : "Stack Overflow",
"related_sites" : [ { "name" : "Stack Overflow Chat",
"relation" : "chat",
"site_url" : "http://chat.stackoverflow.com"
} ],
"site_state" : "normal",
"site_type" : "main_site",
"site_url" : "http://stackoverflow.com",
"styling" : { "link_color" : "#0077CC",
"tag_background_color" : "#E0EAF1",
"tag_foreground_color" : "#3E6D8E"
}
},
{ "api_site_parameter" : "serverfault",
"markdown_extensions" : [ "Prettify" ],
"name" : "Server Fault",
"related_sites" : [ { "api_site_parameter" : "meta.serverfault",
"name" : "Meta Server Fault",
"relation" : "meta",
"site_url" : "http://meta.serverfault.com"
},
{ "name" : "Chat Stack Exchange",
"relation" : "chat",
"site_url" : "http://chat.stackexchange.com"
}
],
"site_state" : "normal",
"site_type" : "main_site",
"site_url" : "http://serverfault.com",
"styling" : { "link_color" : "#10456A",
I want to match strings like
"related_sites" : [ { "name" : "Stack Overflow Chat",
"relation" : "chat",
"site_url" : "http://chat.stackoverflow.com"
} ],
and
"related_sites" : [ { "api_site_parameter" : "meta.serverfault",
"name" : "Meta Server Fault",
"relation" : "meta",
"site_url" : "http://meta.serverfault.com"
},
{ "name" : "Chat Stack Exchange",
"relation" : "chat",
"site_url" : "http://chat.stackexchange.com"
}
],
without enabling multiline. Any idea how to do that?
“Enabling multiline” is exactly how you match multiple lines. That’s why it’s called “multiline”. But since all it does is change
.to include\n, you could just write(.|\n)instead.But given that this is JSON, why on earth are you using a regex on it? Just parse it to a data structure and work from there.