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

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -