How can I make RegEx insert a \n at the last space char before char 65?
I want to do something like word wrap with some long text paragraphs. So If I want a width of 65 or less, I need to repalce the space with \n.
I can insert \n at position 65, but it sometimes ends up in the middle of a word, so I need to backup to the previous space char.
If TextPad RegEx cannnot do this can "normal" RegEx do it? If yes what woould the Search and Replace patterns look like?
I sometimes use this site: http://www.gskinner.com/RegExr/ to test out RegEx, so I would like to use the patterns there where I can save them, and then modify as needed for TextPad.
fixed line length
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
As usual, ben_josephs has a quick and correct solution.
But when I tried it I found that it cannot handle the last word in the paragraphs. That's because there is no trailing space character at the end of the line. So I would suggest that before you run this, you replace "\n" with "_\n" (underscore is a space char). When done you can remove the space by replacing "_\n" with "\n".
This is what I used for testing:
This is some dummy text just to test how the words will look after we do some modifications. This is some dummy text just to test how the words will look after we do some modifications. This is some dummy text just to test how the words will look after we do some modifications.
But when I tried it I found that it cannot handle the last word in the paragraphs. That's because there is no trailing space character at the end of the line. So I would suggest that before you run this, you replace "\n" with "_\n" (underscore is a space char). When done you can remove the space by replacing "_\n" with "\n".
This is what I used for testing:
This is some dummy text just to test how the words will look after we do some modifications. This is some dummy text just to test how the words will look after we do some modifications. This is some dummy text just to test how the words will look after we do some modifications.
Hope this was helpful.............good luck,
Bob
Bob
WOW, did not think TextPad RegEx could look back but you guys found another way. I will try this out in the next few days.
PS - I thought thtt Reformat would do the whole document, but with a RegEx I thought I could do different paragraphs selectively by highlighting them.
Also trying to learn more about RegEx
PS - I thought thtt Reformat would do the whole document, but with a RegEx I thought I could do different paragraphs selectively by highlighting them.
Also trying to learn more about RegEx
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact: