1

I am trying to add grep to a paragraph style so that different character styles are automatically added to some list text that is separated by ; so that each item is a different colour. In the example below 'ABC', DEFGH' etc start each item and they either end with a ; or . at the end. These are consistent throughout and will mostly start with the same set of letters, so that CS1 would apply to ABC, CS2 would apply to DEFGH, etc.

Example text:

ABC xHdisn 57 daad nsm para 10; DEFGH sacas eqdd addwqd 49 dsade para 6; IJKLMN adqdw dq wuwe para 4.

I'm fairly new to GREP. How can I make it so that eg CS1 only applies to "ABC... ;" CS2 only applies to "DEFGH... ;" etc.

2 Answers 2

0

There are probably different ways to achieve this, but here's what I came up with.

  • apply CS1 to ABC.+\;
  • apply CS2 to DEFGH.+\;

enter image description here

2
  • This is great and works well for text ending in ; When text ends in . it is doesn't apply and using the same with . overrides it. Still, it works well for most of my text - thanks!
    – Lind
    Commented Aug 22 at 9:16
  • Using GREP is a trial and error situation, you need to experiment until it works with your specific setup, you can add more rules in the style, etc. Also the GREP queries can be formulated differently to cover more possible outcomes. You can try to replace "\;" with "\." for full stops.
    – lmlmlm
    Commented Aug 22 at 9:52
0

Not able to comment yet, so building on lmlmlm’s answer to include variations:

  • Apply CS1 to ABC.+[.;]
  • Apply CS2 to DEFGH.+[.;]

Or for tighter control, you can specify that the wildcard character not be one of your two delimiters:

  • Apply CS1 to ABC[^.;][.;]
  • Apply CS2 to DEFGH[^.;][.;]

Or if you want to match the “not” with the “is”,

  • Apply CS1 to (ABC[^.]\.)|(ABC[^;]\;)
  • Apply CS2 to (DEFGH[^.]\.)|(DEFGH[^;]\;)

Note that characters are literal (escaped) by default in character classes ([]). So while $ matches “end-of-line,” [$] matches the literal dollar sign character. (To match end-of-line within the character class, use [\$] to “unescape” it.)

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.