I am trying to format a part of a paragraph (I have the paragraph style) with GREP.

It is the caption of some photos and the phrases are divided by the sign of "|": This is phrase 1 | This is phrase 2

I would like to use GREP to style only phrase 1 (with character style), but I get dizzy with the commands GREP.

  • Welcome to GD.SE! Can you show us an example of what you tried to do?
    – Mensch
    Jan 5 at 16:38

1 Answer 1


You could use this GREP expression to select the first phrase:

.+(?= \|)

Let's have a look at the individual parts of the expression.

  • .+
    This searches for Any Character . repeated One or More Times +.

  • (?= \|)
    This is a Positive Lookahead which searches for text that comes before a space followed by a vertical bar \|. We need to unescape the | with a \ because it has a special use in GREP.

So the expression is searching for: One or more characters that comes before a space followed by a vertical bar.

Bonus tip

Add a GREP Style to the Paragraph Style to automatically format all instances of phrase 1 with a certain Character Style. Like this:

enter image description here

  • Thanks, Wolf! but I was wrong to point to the text, the correct is: This is phrase 1 | This is phrase 2 it does not include parentheses. Tried testing the theory but I think I'm still a GREP beginner. EDIT I do it! (?<=.).+(?= \|) Thanks again, Wolf! Jan 5 at 17:22
  • Ah. You shouldn't have included the parentheses in the code formatting then. Can't you just use .+(?=\|)? One or more characters before a space followed by a vertical bar.
    – Wolff
    Jan 5 at 17:28
  • Yes! Working great. My code was not selecting the first letter. Thanks again, @wolf. Jan 5 at 17:31
  • OK, I have edited your question for you. I will also edit this answer accordingly. Please remember to accept it at some point. 😀
    – Wolff
    Jan 5 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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