Skip to main content
Alex Grant
Inspiring
August 2, 2019
Answered

GREP style formatting a line preceded/followed by another line in Indesign CC 2017

  • August 2, 2019
  • 1 reply
  • 1967 views

Hello all,

I'm having hard time devising a working GREP expression to format a calendarium I'm working on.

I have a text field structured as follows:

...

M(tab)(some number)

T(tab)(some number)

W(tab)(some number)

T(tab)(some number)

F(tab)(some number)

S(tab)(some number)

S(tab)(some number)

M(tab)(some number)

T(tab)(some number)

W(tab)(some number)

T(tab)(some number)

F(tab)(some number)

S(tab)(some number)

S(tab)(some number)

...

And this pattern repeats for the whole month. The numbers obviously start at 1 and go to 28-31 (e.i. some are single digit, others are double digit).

I want to put an underscore between the second S (Sunday) line and the M (Monday) line, so that it separates them, say like this:

...

M(tab)(some number)

T(tab)(some number)

W(tab)(some number)

T(tab)(some number)

F(tab)(some number)

S(tab)(some number)

S(tab)(some number)

M(tab)(some number)

T(tab)(some number)

W(tab)(some number)

T(tab)(some number)

F(tab)(some number)

S(tab)(some number)

S(tab)(some number)

...

But whatever I try InDesign GREP option in the Paragraph style it refuses to understand me.

If I just do:

S\t\d+

Obviously works but underscores both Saturday and Sunday lines.

Here are some examples of the many GREP expressions I've tried the past two days with no success:

(?<=S\t\d+\r)S\t\d+

(?<=^S\t\d+\r)S\t\d+

(?<=S\t\d+$)S\t\d+

(?<=^S\t\d+$)S\t\d+

(?<=S\t\d+~b)S\t\d+

S\t\d+\r(?=M)

S\t\d+~b(?=M)

What am I missing?

This topic has been closed for replies.
Correct answer Jongware

Hello Jongware,

That is the first thing I did when I hit the "wall", but the problem is when I need to reflow the textfield in columns (2 on my screenshots, but may be even more), in order to have the weeks as separate blocks, I would prefer to have the underline at the end of the block, rather than at the beginning of the next one.

I can't believe there is no way to look beyond a paragraph... I read some other online resources that described similar problems to mine, but couldn't use those examples to construct something for my case. So how are they different than what I'm trying to achieve?

The InDesigner » Blog Archive » An Undocumented Bit of GREP Gold

https://stackoverflow.com/questions/35068678/use-regex-to-match-certain-number-of-lines-that-follow-the-line-containing-… 


alexanderg59976277  wrote

I can't believe there is no way to look beyond a paragraph... I read some other online resources that described similar problems to mine, but couldn't use those examples to construct something for my case. So how are they different than what I'm trying to achieve?

Both of your examples use a regular GREP find/replace, not a GREP style. GREP Styles just do not look beyond their own paragraph. Treat it as a fact of life.

(There may be a deep technical reason for it. For example: if testing beyond the current paragraph is possible, then the resulting formatting on a certain paragraph depends on any next – or previous! – paragraph. In the Find/Change dialog, InDesign has no problems at all with looking either forwards or backwards, for many, many paragraphs. So – if this was implemented in GREP styles, then changing a single letter of text at the very start of a document would require testing all GREP styles of the entire story – because any one of them could check for the presence or absence of that very first character.

(Yes, it'd make GREP styles unbearably slow. Pretty unbelievably but yes, even more than with the current implementation. To compare: as I see it, what the current implementation does is to re-run each GREP style in every paragraph style, every time that paragraph needs displaying. Nothing is cached. Now imagine that on a document-wide scale.))

Back to Topic. Now that GREP Styles are out of the way, we might also discuss whether you need one. Do you sometimes use different day-of-the-week letters? Can they appear in any order? Do you often remove, add, or move the days of the week around?

If the answer to all of these questions is "no", then no, you don't "need" a GREP style. Just use one of your previous search-and-replaces to set the correct character or paragraph style to your day of choice. Do remember that the main reason that they did not work was that you tried them inside a GREP style.

1 reply

Sunil Yadav
Legend
August 2, 2019

Can you share some screenshot of your document/work?

Alex Grant
Inspiring
August 2, 2019

Sure

Here is a screenshot of when using: S\t\d+

Here is what happens (or rather not happens) when using any of the other expressions I tried:

Community Expert
August 2, 2019

This does not seem to be a scripting issue. I will transfer this to the general InDesign forum so that you could get a wider audience and better ideas.

-Manan

-Manan