Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Simon8888

macrumors newbie
Original poster
Feb 14, 2016
2
0
Hi, does any one know a good grep formula in Indesign for removing paragraph breaks before lowercase letters, and replacing them with a space?

When I try it finds the lowercase letter, but highlights it also, meaning that the lowercase letter will also be replaced along with the paragraph break. Anyone know how to get it to just find the paragraph break?

Thanks
Simon
 
I'm not familiar with InDesign, and only a rookie with GREP, but I can tell you how this would work in a text editor like TextWrangler (which may help if you can do something similar in InDesign).

The rough idea is to search for "paragraph break followed by lowercase letter", then replace with "space followed by the same lowercase letter."

In TextWrangler I'd search for "\r([a-z])" (a line break followed by a single lowercase letter) then replace with " \1". The \1 is a reference to the expression found in parentheses, so in this case, it's whichever single lowercase letter was found right after a line break. This lets you essentially re-insert that letter where it was, but replace whatever was before it.
 
You can use a positive lookahead in InDesign like so:

\r(?=[a-z])

Basically it means a return followed by any character a-z, but the match does not *contain* the a-z character... if that makes any sense.

Note that if you have to consider any languages with lowercase characters other than a-z (e.g. Greek, Russian etc) then you'll need to to a little tweaking.
 

Attachments

  • greps.jpg
    greps.jpg
    89.9 KB · Views: 421
You can use a positive lookahead in InDesign like so:

\r(?=[a-z])

...
Note that if you have to consider any languages with lowercase characters other than a-z (e.g. Greek, Russian etc) then you'll need to to a little tweaking.

... and you possibly need to deal with numerals and mid-sentence symbols (e.g. $, &, (, ", en dash, em dash, ...) following the spurious line break. You also won't be able to distinguish between mid-sentence capitals.

It might be better to search for line breaks not preceded by periods. I'm not a code meister so perhaps someone else can post the code to do this.
 
Just for the sake of completeness: InDesign has some metacharacters for situations such as the ones we've touched on (e.g. non latin languages). You could use something like:

Code:
\r(?=\l)

...to match lowercase characters which I expect will include non-latin characters. Exactly what InDesign considers lower case, I don't know so I guess you'd need to do some experimenting and testing. There are some fun situations in languages such as Georgian!

There's a full list of meta characters for InDesign here:


http://www.jetsetcom.net/images/downloads/list_of_grep_symbols.pdf
 
I'm not familiar with InDesign, and only a rookie with GREP, but I can tell you how this would work in a text editor like TextWrangler (which may help if you can do something similar in InDesign).

The rough idea is to search for "paragraph break followed by lowercase letter", then replace with "space followed by the same lowercase letter."

In TextWrangler I'd search for "\r([a-z])" (a line break followed by a single lowercase letter) then replace with " \1". The \1 is a reference to the expression found in parentheses, so in this case, it's whichever single lowercase letter was found right after a line break. This lets you essentially re-insert that letter where it was, but replace whatever was before it.

Thank you, I think the GREPS are similar so I can try this. Thanks for your time
[doublepost=1455733100][/doublepost]
... and you possibly need to deal with numerals and mid-sentence symbols (e.g. $, &, (, ", en dash, em dash, ...) following the spurious line break. You also won't be able to distinguish between mid-sentence capitals.

It might be better to search for line breaks not preceded by periods. I'm not a code meister so perhaps someone else can post the code to do this.

Ah clever, thank you for this advice!
[doublepost=1455733231][/doublepost]
You can use a positive lookahead in InDesign like so:

\r(?=[a-z])

Basically it means a return followed by any character a-z, but the match does not *contain* the a-z character... if that makes any sense.

Note that if you have to consider any languages with lowercase characters other than a-z (e.g. Greek, Russian etc) then you'll need to to a little tweaking.

Wow that's brilliant, your formula worked perfectly, you've saved me 2 days of deleting paragraph returns!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.