Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

103.Advanced search and replace -- How to add hard returns to limit line length to 40, but without breaking word?

User: editor -- 2008-05-15          << 102  104 >>
Hits: 2711
Type: Advanced search and replace   
Search all Advanced search and replace examples
How to add hard return for a text file, and limit each line to less than 40 characters, and don't break word?
Input Sample:
More than 4.3 million homes collapsed or sustained damage, according to the Chinese Embassy in Washington, and the official death toll from the quake had reached 14,866 by Wednesday evening.
But casualty figures from various cities indicate a higher number of dead.
Output Sample:
More than 4.3 million homes collapsed or 
sustained damage, according to the 
Chinese Embassy in Washington, and the 
official death toll from the quake had 
reached 14,866 by Wednesday evening.

But casualty figures from various cities 
indicate a higher number of dead.
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
1. ctrl-o open source file
2. ctrl-h open 'replace' dialog, set 
1) set 'Replace Unit' to Chars
2) set 'Replace Scope' to Line
3) set 'search for pattern': 

4) set 'replace with pattern':

3. click 'Replace' 

1. step 1, 3) use 'regular expression', so need to uncheck 'enhanced regular expression'.
2. '.{2,40}( |$)' means 2 to 40 characters followed by a space or line end.
3. $match\n means add a '\n' for each matched text.
Download Script:  scripts/

Screenshot 1:  Replace_Window

Similar Examples:
How to limit each line to specified length without breaking word? (66%)
How to wrap text by adding return but without breaking words? (63%)
How to remove all duplicated lines without considering the last word? (49%)
How to sort a text file by the length of text in each line? (48%)
How to find all lines in file A that contain words in file B? (47%)
How to add a '*' at the beginning of each line that contains keyword "PASS"? (47%)
How to extract all lines that contain A, but not any of B C D? (47%)
How to remove all lines containing 'test1' and 'test2' but without 'test3'? (47%)

Check Demo of Advanced search and replace
limit line length  without break  hard return  hard  enhanced regular expression  line length  break  less  length  return  regular expression line length  returns line  returns line length  word replace return with space  replace return with space  add line break  with less characters  text file by line length