Say I have some text in the following format:

Text before formatting

What I am trying to style, using GREP, is the beginning of every new paragraph (that comes after an empty line), until a digit or return is reached, so that it would look something like this:

Text after formatting

I've been using regexr to try and find a solution, but it appears not be 100% compatible with InDesign's GREP utility.

2 Answers 2


Updated Answer:

The problem is that using a paragraph break for every new line means that every line is a paragraph and using GREP paragraph styles you can only target a single paragraph. Theres no way to tell if you are on the first line because every line is the first line. The only way to get around that would be to test if the paragraph before is empty.. which I don't think is possible.

If changing the paragraph breaks to soft breaks you can use this:


If changing the breaks isn't an option I havn't got a workaround for the paragraphs without numbers but you can target just the ones with using this:


Original Answer:


An explanation -

^ matches the beginning of the paragraph

. matches any character

*? matches 0 or 1 time (so we only match up to the first digit)

(?=) looks ahead (matches up to but not including what's in the parenthesis)

\d matches any digit

| OR

\n matches a line break

For reference, All of this can be found on the InDesign help.

  • Thanks for the attempt, but I'm afraid it's not right. This catches absolutely everything that precedes the final paragraph. So it would style everything up to (but not including) "vim at omittam urbanitas scribentur" in my example above.
    – verism
    Commented Jan 14, 2016 at 12:08
  • OK - I tried ^.*?(?=\d|\n) (not \r as in your example) and that's very close. It's not working for the third paragraph in my example though
    – verism
    Commented Jan 14, 2016 at 12:10
  • Strange, I'll have to try once I can open ID later.
    – Cai
    Commented Jan 14, 2016 at 12:11
  • Appreciated. And, just to be clear, the only place it's failing is the third paragraph; it doesn't style the first line, but it does the subsequent ones until a digit is reached.
    – verism
    Commented Jan 14, 2016 at 12:13
  • How are you doing the new lines, are they paragraph breaks or soft line breaks?
    – Cai
    Commented Jan 14, 2016 at 12:15

This is not a GREP based solution, but maybe it's good enough for you. It would require to change your paragraph breaks into line breaks (which, given the context, would be the correct way to go?).

Just use a nested line style, and it'll style the first line of every paragraph, no matter what is there.

nested line style

  • Thanks for the suggestion - it doesn't quite fit my criteria though, as it styles everything on the first line, not just everything up to the first digit. Out of interest though, how do you specify a line break, rather than a paragraph break?
    – verism
    Commented Jan 12, 2016 at 12:48
  • Oh you're right! Absolute slip of the mind, sorry about that. I'll take a closer look at GREP, I was unable to target what you need in my tests. You can do line breaks by shift + return instead of just return
    – MrMerrick
    Commented Jan 12, 2016 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.