{"id":13231,"date":"2010-08-16T18:48:50","date_gmt":"2010-08-17T01:48:50","guid":{"rendered":"http:\/\/www.kith.org\/journals\/jed\/2010\/08\/16\/13231.html"},"modified":"2010-08-16T18:48:50","modified_gmt":"2010-08-17T01:48:50","slug":"double-your-indentation-with-r","status":"publish","type":"post","link":"https:\/\/www.kith.org\/jed\/2010\/08\/16\/double-your-indentation-with-r\/","title":{"rendered":"Double your indentation with regular expressions!"},"content":{"rendered":"\n<p>Say you have a code sample where each level of indentation is indented by only one space more than the previous level:<\/p>\n<pre>\n{\n \"version\": \"1.0\",\n \"superitem\": {\n  \"item\": {\n   \"subitem\": {\n    \"data\": \"test\"\n   }\n  }\n }\n}\n<\/pre>\n<p>Say you want to change the indentation to be two spaces per level.<\/p>\n<p>And say you want to do this using the regular-expression search-and-replace tool in a text editor, like BBEdit.<\/p>\n<p>How would you go about it?<\/p>\n<p>There may be some cleverer way to do it, but I was reasonably pleased with the semi-kludgy approach I came up with.<\/p>\n<p>Search for the following:<\/p>\n<pre>\n^( ?)( ?)( ?)( ?)( ?)( ?)\n<\/pre>\n<p>(In each pair of parens is a space followed by a question mark.)<\/p>\n<p>Replace-all with:<\/p>\n<pre>\n\\1\\1\\2\\2\\3\\3\\4\\4\\5\\5\\6\\6\n<\/pre>\n<p>This is sadly non-general; it relies on there being no more than six levels of indentation. But for my purposes, it works nicely, and is much better than running a series of search-and-replaces.<\/p>\n<p>(I know I said I wasn't going to blog this week, but this is work-related and took only five minutes to write up.)<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Say you have a code sample where each level of indentation is indented by only one space more than the&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[68],"tags":[],"class_list":["post-13231","post","type-post","status-publish","format-standard","hentry","category-programming"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/posts\/13231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/comments?post=13231"}],"version-history":[{"count":0,"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/posts\/13231\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/media?parent=13231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/categories?post=13231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kith.org\/jed\/wp-json\/wp\/v2\/tags?post=13231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}