2

I have a sequence of titles and description in my text following a pattern similar to

Data A: foo; Data B: bar; Data C: baz; Data D: qux

I want to bold just the titles, so I wrote the following GREP styles: ^[^:]*: (from the beginning to :, a string with no :) and (?<=;\s)[^:]*: (from the ; excluded to :, a string with no :)

It works pretty fine:

Data A: foo; Data B: bar; Data C: baz; Data D: qux

If one of the descriptions includes a ; , though, that GREP produces an unwanted result:

Data A: foo; bar; Data C: baz; Data D: qux

I tried removing ; from the accepted pattern: (?<=;\s)[^(;\s):]*: but it just skips the whole block, as if it checked the first ; to the following :, found that whatever was inside didn't match and started regexing again from after the colon:

Data A: foo; bar; Data C: baz; Data D: qux

How do I tell inDesign to start the GREP from the ; closest to the next colon?

This, by the way, is the intended result:

Data A: foo; bar; Data C: baz; Data D: qux

0

You can’t do grouping inside character classes, so [^(;\s):]* is not valid – or rather, it doesn’t mean what you want it to mean. Parentheses are not special characters that create groups inside character classes; they’re literal characters. So it means ‘one or more of any character which is not an opening parenthesis, a semicolon, a space, a closing parenthesis or a colon’.

I’m sure you can see the problem here: the string you’re searching for must:

  • follow a semicolon + space
  • start with one or more characters which are not parentheses, semicolon, colon or space
  • end with a colon

Since GREP is greedy by default, the first possible matching string will be bar; Data C:. While that does satisfy the first and third requirements (follows a semicolon + space, ends with a colon), it contains several spaces, which your character class said it couldn’t, so the match fails. In fact, since all the bits you want to highlight contain spaces, none of them will match.

(Note: In the question, you’ve bolded Data D: at the end, but that shouldn’t match either, and in my InDesign, it doesn’t match. Only Data A: gets bolded for me.)

The easiest solution is to simply leave out the space (and the parentheses) from the negated character class and only check for characters which are not semicolons or colons:

(?<=;\s)[^;:]*:

The only downside to this is that it will also make the space following the semicolon bold – but you can’t tell a regular space from a bold space in typeset text in InDesign, so this doesn’t seem like it’s likely to cause problems.

1
  • Unfortunately I'm not able to upvote from this unsigned account I use at work, but I will upvote you from my home account :) – Firefighter Dec 18 '20 at 7:43

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.