Highlighted

GREP to find all the space before the last word of a paragraph.

Community Beginner ,
May 26, 2020

Copy link to clipboard

Copied

I need to find all the space before the last word of a paragraph. to replace it with a Non breaking space to avoid a single word in a line. 

For example:

shuaces_1-1590500445372.png

to avoid the word "change" being alone, I replaced the space before it with a non breaking space.

shuaces_2-1590500451143.pngshuaces_3-1590500452844.png

If you have other suggestion to solve this, feel free to comment.

Thank you in advance.

 

Adobe Community Professional
Correct answer by Barb Binder | Adobe Community Professional

A better approach—IMHO—is to use a GREP style to eliminate short words from appearing alone on the last line.

  1. Create a character style that enables No Break (it's a checkbox in Basic Character Formats).
  2. Add a nested GREP style to your Body paragraph style to assign your new character style to: .{8}\z

 

This means: assign the character style to a string of 8 letters at the end of a paragraph or at the end of the tory. The number can be adjusted a bit, if that makes you happy to apply it to 9 or 10 characters, for example, dependent on line length.

 

Not only will you not have the issue with long words not able to break—whick would be awful—but this works in realtime so as you edit the document it will dynamically adjust. Find/change only happens when you run it.

 

~Barb 

TOPICS
How to, Type

Views

564

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

GREP to find all the space before the last word of a paragraph.

Community Beginner ,
May 26, 2020

Copy link to clipboard

Copied

I need to find all the space before the last word of a paragraph. to replace it with a Non breaking space to avoid a single word in a line. 

For example:

shuaces_1-1590500445372.png

to avoid the word "change" being alone, I replaced the space before it with a non breaking space.

shuaces_2-1590500451143.pngshuaces_3-1590500452844.png

If you have other suggestion to solve this, feel free to comment.

Thank you in advance.

 

Adobe Community Professional
Correct answer by Barb Binder | Adobe Community Professional

A better approach—IMHO—is to use a GREP style to eliminate short words from appearing alone on the last line.

  1. Create a character style that enables No Break (it's a checkbox in Basic Character Formats).
  2. Add a nested GREP style to your Body paragraph style to assign your new character style to: .{8}\z

 

This means: assign the character style to a string of 8 letters at the end of a paragraph or at the end of the tory. The number can be adjusted a bit, if that makes you happy to apply it to 9 or 10 characters, for example, dependent on line length.

 

Not only will you not have the issue with long words not able to break—whick would be awful—but this works in realtime so as you edit the document it will dynamically adjust. Find/change only happens when you run it.

 

~Barb 

TOPICS
How to, Type

Views

565

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 26, 2020 0
Adobe Community Professional ,
May 26, 2020

Copy link to clipboard

Copied

Find Grep

( *?)(\w+?\r)

Change To

~S$2

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 26, 2020 1
Most Valuable Participant ,
May 26, 2020

Copy link to clipboard

Copied

Hi @shuaces,

you have small columns in your document.

That's why my question: Do you really mean this is a good idea?

 

What is if there are very long or very short words at the end of your paragraphs?

last_words_01_not_applied.pnglast_words_02_applied.pnglast_words_03_applied.pnglast_words_04_applied.png

 

Nevertheless - I did use a similar grep style in a paragraph style for this example:

( *?)(?=\w+[.!?]\r)

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 26, 2020 1
Adobe Community Professional ,
May 26, 2020

Copy link to clipboard

Copied

A better approach—IMHO—is to use a GREP style to eliminate short words from appearing alone on the last line.

  1. Create a character style that enables No Break (it's a checkbox in Basic Character Formats).
  2. Add a nested GREP style to your Body paragraph style to assign your new character style to: .{8}\z

 

This means: assign the character style to a string of 8 letters at the end of a paragraph or at the end of the tory. The number can be adjusted a bit, if that makes you happy to apply it to 9 or 10 characters, for example, dependent on line length.

 

Not only will you not have the issue with long words not able to break—whick would be awful—but this works in realtime so as you edit the document it will dynamically adjust. Find/change only happens when you run it.

 

~Barb 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 26, 2020 2