1

I have the following sample text:

Writing: Gnusto. Editing: Caskly. Circulation: Izyuk.

I'm trying to use a GREP regex to select only the job titles and colons (i.e. "Writing:", "Editing:", "Production:"). The following works on this online regex tester:

^[^:]*:|(?<=\. )[^:]*:

However, when I try it on InDesign Find/Change..., it only selects "Writing:".

The issue seems to be with the interpretation of the OR (|) operator. The expression to the left of the | will successfully select "Writing:". The expression to the right will successfully select "Editing:" and "Art:" - in fact, if I remove the left expression and the |, InDesign will indeed select them.

The | means either/or in standard regex languages, which means both expressions on either side will be tested for a match. However, here, it's as if InDesign can't interpret the | and just stops at it. Is this correct and if so, is there another part of the regex dialect supported by InDesign that can do what I'm looking for? Thanks!

UPDATE: I got it to work! All I did was switch ordering of the expressions around the |:

(?<=\. )[^:]*:|^[^:]*:

So my problem is fixed, but I'm leaving the question up because the developer in me wants to know what is going on here - some kind of evaluation order unique to InDesign's regex engine, or something else?

1
  • Lookbehinds are a bit special in regexp engines and are really sensitive to placement in some. Idea is that regexp engines do not want to backtrack if not neccesery. Different implementations on this are very differently sensitive. I dont exoect this to be indesign soecific but rather than your tester works with a different engine. To be honest i would or the subexpression with the position or lookbehind. Anyway your regexp is conceptually a bit problematic since your using it as a replacement for a parser.
    – joojaa
    Commented Dec 9, 2021 at 1:45

1 Answer 1

2

InDesign has a number of special GREP characters you can use to your advantage. They can be accessed clicking the @-symbol next to the Find what and Change to fields.

In this case you can simply use: \w+:.

This means: Any word character (\w) one or more times (+) followed by a colon (:).

You can use Find/Change to apply a Character Style to apply a certain Character Style to all occurrences or you can add a GREP Style in your Paragraph Style to automatically style all occurrences with the wanted Character Style. Like this:

2
  • I was answering while you edited your question. It sort of changed from a "How do I do this?" to a "Why can't I do this?" question. I'm not sure actually. I think it has more to do with the positioning of the Positive Lookbehind than the or operator.
    – Wolff
    Commented Dec 9, 2021 at 1:09
  • Sorry was editing while you were answering. Both your answer and this comment are helpful - thanks!! I think it may be the lookbehind, like you said. Commented Dec 9, 2021 at 3:35

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.