Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

GREP: automatically return single short word after period at end of line?

Advocate ,
Jun 25, 2023 Jun 25, 2023

I'd like to know how to use GREP to identify lines that end with a period, then a space, then a word shorter than five characters, then any/no space before a line return.

 

So, if I have:

aaaa aaaaa a aaaaaa aaa aa aaaa aaaaaaaa. Cars

 

It will become:

aaaa aaaaa a aaaaaa aaa aa aaaa aaaaaaaa.
Cars

I've been searching online as well as trying to find an answer in Kahrel's GREP, to no avail...

Any help appreciated.

TOPICS
Type
864
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Hi @turner111 

I'm not sure I understood you correctly. Do you mean something like this?

find:

\w\.\K(\h)(?=\w{1,4}\r)

replace with:

\r

 

This only works with Grep Find & Replace - not in a Grep style.

before:

aae01.pngexpand image

 

result:

aae02.pngexpand image

If that works for you

have fun

😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 25, 2023 Jun 25, 2023

Thanks - I'll try this out, but it needs to be something that works with a style so that the text will continually reflow.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Sorry, in my opinion this cannot work with a Grep style.

 

But who knows?

Let's just wait and see. Other mothers have smart children too.

😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

To the best of my knowledge GREP cannot identify the end of a line, only the end of a paragraph or at a forced break of some sort, so I think this would require scripting and is not something that can be added to a style. In my opinion it would really bog down the program if it were constantly re-parsing the text to see if you've made an edit that changes a line ending ad requires a new shift, which in turn may require yet another. It would be a nightmare with the paragraph composers, and only slightly better with single-line composers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Which begs the clarification:

 

@turner111 By "line break" do you mean text that appears at the end of a line or text that appears at the end of a paragraph?

 

As per @Peter Spier, you won't be able to use a regular expression to match the end of a line. Peter Kahrel's book lists the five of the seven locations on page 25, and then covers the two additional locations—\A and \z to match beginning and end of story—as you continue to work through chapter 4.

 

~Barb

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 26, 2023 Jun 26, 2023

Hi Barb,

Line break, excluding paragraph ends... oh well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023
  • (manuel) line break in grep is \n
  • end of paragraph in grep is \r
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 26, 2023 Jun 26, 2023

Hi,

I'm referring to a natural (non-manual) line break.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Not possible with GREP, nor a style.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2023 Jun 26, 2023

… Mischievously doable with a Grep style!

 

Char style: _JumpToNextLine

Grep expression: \.\K\h(?=\w{1,4}\h?$)

 

Capture d’écran 2023-06-26 à 13.11.27.pngexpand image

 

(^/)  The Jedi

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

You seem to assume that each of these is a separate paragraph. OP has explicitly said this is running text and he simply doesn't want short words starting a new sentence at the right margin.Short word sentence start.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2023 Jun 26, 2023

… Always mischievously doable with a Grep style!

 

Char style: _JumpToNextLine 2

Grep expression: \.\h\K(\w{1,4}\h)

 

Capture d’écran 2023-06-26 à 14.01.52.pngexpand image

 

(^/)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

But what is this style doing to the format to cause that word to move? You've told us how to find the word (though not limited to end of line, it seems), but you've told us nothing about how you move it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2023 Jun 26, 2023

Not at all but you don't seem to read the "French" language!

 

"Sans retour automatique" means "No break"!

 

(^/)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

typing while you were posting...

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

OK, I don't speak French, but I've found a clue in the screen shot. Your style applies No Break.

That's actually pretty clever.

Applying No Break to all words shorter than 5 characters plus the following space shouldn't hurt anything mid-line, though I question how much drag it will have on performance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2023 Aug 08, 2023
LATEST

I CANNOT thank you enough! I have been looking for a way to do this! It works perfectly. I wanted to avoid beginning a two-letter word at the end of a line. This is brilliant.

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