regex - replace all line breaks not precede by a period with a regular expression? -


is possible select line breaks not preceded period using regular expressions ? editing subtitles files students. make printed version dead tree friendly trying replace line breaks not preceded period or question mark space.

option 1
select line breaks not preceded period or question mark regex [a-z]\n works of course selects last letter of word before line break. -> possible somehow save , insert last letter of word before line break , insert space using regular expressions or have write script (say php)

option 2
select line breaks preceded character. tried looking lookbehind.

while writing question solution hit me. select line break precede character (?<=[a-z])\n , replace space.

i searched stack overflow , not find looking for. hope not offend posting question , solution @ same time. might else in future.

the syntax can vary depending on using replace text (java, perl, php, sed, vi, etc.).

in java try :

str.replaceall("([^\\.!?])\r?\n", "$1 ").replaceall("  +", " "); 

in perl :

perl -p -e 's/([^\.!?])\n/\1 /g; s/  +/ /g;' file.txt 

you can read answer similar question :

how can replace newline (\n) using sed?


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -