Copy link to clipboard
Copied
I have this working, but wanted to make sure I did not overlook something.
My book looks best with a character style "No break" applied as a grep style within my paragraph style. Because the book is in Spanish, there are some very short words I wanted to account for. I chose 5 words as the quantifying value.
Here is my GREP. Let me know if I have left out anything.
\w{5}
So you did mean word,not word character. Your \w{5} means 'keep 5 word characters together'. To keep 5 words together at the end of the paragraph (which is excessive by any standard), you need this:
(\h[^\s]+){4}$
Copy link to clipboard
Copied
My language environment is Japanese, but the regular expression part would be helpful.
Note that it is a backslash, not a slash.
Copy link to clipboard
Copied
Very cool, Ajabon. Are these approaches just different with the same result, or do they add on checks and balances to mine? Thanks!
Copy link to clipboard
Copied
I divided the regular expression into three parts because I thought it would be better to emphasize visibility than to write it on a single line in a cool way.
The first is at the beginning of a paragraph, the second in the middle of a paragraph, and the third at the end of a paragraph. But this may not be necessary since I think there is usually punctuation at the end of a line. But just in case.
Regards.
Copy link to clipboard
Copied
Hi @MadMac55 , have you considered setting a Hyphenation rule in your Paragraph Style?
Setting Words with at Least to 6 would prevent any words with 5 characters or less from breaking:
Copy link to clipboard
Copied
Thanks, Rob. The style for body text in the book is justified, no hyphenation, so that alone wouldn't keep a minimum word count at the end of a paragraph where No Break actually impacts it.
Copy link to clipboard
Copied
> I chose 5 words as the quantifying value.
You mean 5 word characters (letters and digits), right?
Copy link to clipboard
Copied
Mr Kahrel! No I meant words. Because the book is Spanish, there are very short words that could encourage very short lines (this sounds picky, but...). So, to minimize the presentation of the short lines, I used an arbitrary number of words (5) to have the No Break control the presentation. If that makes sense.
As I poured my first coffee, I did have a thought along this line that I did not take into account digits and should have included /w|/d
Copy link to clipboard
Copied
So you did mean word,not word character. Your \w{5} means 'keep 5 word characters together'. To keep 5 words together at the end of the paragraph (which is excessive by any standard), you need this:
(\h[^\s]+){4}$
Copy link to clipboard
Copied
After testing, I believe the \h was hanging this up. I was wrong; it was an extra space between words that caused the problem. Works great. Thank you again.
Copy link to clipboard
Copied
Peter, can you explain the "\h" ? I looked this up in Reg-ex for what it symbolizes, but it's escaping that character. Why that character?
Copy link to clipboard
Copied
\h stands for 'horizontal space', it covers all space characters (normal, en, em, fixed, etc.) and the tab. Not the return characters. What that character? To avoid the paragraph resurn and to capture normal and fixed-width spaces. You could use \s as well probably (any space, including the paragraph mark).
Copy link to clipboard
Copied
Great one. I could not find that. I bet if I go back to your GREP book I will. Jesus. Thanks for the explainer.