{"id":5535,"date":"2016-07-13T14:51:07","date_gmt":"2016-07-13T19:51:07","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=5535"},"modified":"2016-07-13T15:09:44","modified_gmt":"2016-07-13T20:09:44","slug":"how-to-replace-newlines-and-maintain-the-surrounding-text","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2016\/07\/13\/how-to-replace-newlines-and-maintain-the-surrounding-text\/","title":{"rendered":"How to replace newlines and maintain the surrounding text"},"content":{"rendered":"<p>Using regular expression groups, we can instruct whatever software we happen to be using what we want to replace.  For example assuming we want to replace all newlines followed by a digit, we can use what is below in Textpad&#8230;<\/p>\n<p><img alt='' class='alignnone size-full wp-image-5537 ' src='http:\/\/appcrawler.com\/wordpress\/wp-content\/uploads\/2016\/07\/img_578694155ce94.png' \/><\/p>\n<p>&#8230;while keeping the newline for those lines that are not followed by a digit.<\/p>\n<p>You can do something similar in python with the following&#8230;<\/p>\n<pre>\r\n>> import re\r\n>>> s=\"steve\\n01\\nbec\\nky\"\r\n>>> print s\r\nsteve\r\n01\r\nbec\r\nky\r\n>>> t = re.sub(r'\\n+([0-9].*)',r' \\1',s)\r\n>>> print t\r\nsteve 01\r\nbec\r\nky\r\n>>>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using regular expression groups, we can instruct whatever software we happen to be using what we want to replace. For example assuming we want to replace all newlines followed by a digit, we can use what is below in Textpad&#8230;&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2016\/07\/13\/how-to-replace-newlines-and-maintain-the-surrounding-text\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[72],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5535"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=5535"}],"version-history":[{"count":5,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5535\/revisions"}],"predecessor-version":[{"id":5542,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5535\/revisions\/5542"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5535"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}