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

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

Advocate ,
Jun 25, 2023 Jun 25, 2023

Copy link to clipboard

Copied

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

Views

451

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
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Copy link to clipboard

Copied

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.png

 

result:

aae02.png

If that works for you

have fun

😉

Votes

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
community guidelines
Advocate ,
Jun 25, 2023 Jun 25, 2023

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Copy link to clipboard

Copied

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.

😉

Votes

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
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Community Expert ,
Jun 25, 2023 Jun 25, 2023

Copy link to clipboard

Copied

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

 

 

Votes

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
community guidelines
Advocate ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

Hi Barb,

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

Votes

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
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

  • (manuel) line break in grep is \n
  • end of paragraph in grep is \r

Votes

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
community guidelines
Advocate ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

Hi,

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

Votes

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
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

Not possible with GREP, nor a style.

Votes

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
community guidelines
LEGEND ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

… 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.png

 

(^/)  The Jedi

Votes

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
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

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.png

Votes

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
community guidelines
LEGEND ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

… 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.png

 

(^/)

Votes

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
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
LEGEND ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

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

 

"Sans retour automatique" means "No break"!

 

(^/)

Votes

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
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

typing while you were posting...

 

Votes

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
community guidelines
Community Expert ,
Jun 26, 2023 Jun 26, 2023

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Explorer ,
Aug 08, 2023 Aug 08, 2023

Copy link to clipboard

Copied

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.

Votes

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
community guidelines