Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP for applying character style to phrase between …

Tagged: 

Return to Member Forum

  • Author
    Posts
    • #116587
      Colleen Kiefer
      Participant

      I have a huge publication in which the client wants all “affiliations” to be in italics. So it looks like this: V.I. Person, University of Hooterville; M. KnowItAll, InDesign Secrets; S. Little, Genius Lab, SmallTown; …. I’m trying to figure out if I can search for everything that falls between a comma and a semicolon and apply a character style to it. As you can see there will be a few cases where there’s an additional comma in the person’s affiliation. For example, C. Kiefer, Univeristy of California, Santa Barbara; …
      How might I modify this bit of GREP I found in another article: (?<=\().+?(?=\))
      It seems similar to finding anything between a set of parentheses, but not including thm. Any help would be appreciated. Thanks in advance.

    • #116588
      Jeremy Howard
      Participant

      Hey there! What you are trying to do is very similar to the GREP string that you provided in your post. Here’s what you’re after:

      (?<=,).*?(?=;)

      A breakdown of the GREP string:

      (?<=,) – this is a positive look-behind, that is saying that we only want to find characters that come directly after a comma and a space.

      .*? – this is “zero or more characters” the reason that I opted for this instead of the “.+” is because “.*?” is what’s known as a non-greedy specifier. It will match the minimum amount of characters before it stops formatting. On the other hand, “.+” is a greedy specifier, it will match as much as it possibly can before it stops applying the formatting. This causes issues when you are trying to access small piece of text within a list.

      (?=;) – this is a positive look-ahead. This is saying that we only want to format the text that comes before the semi-colon and lets the GREP string know where it should stop formatting characters.

      This solution will work for single and multiple comma affiliations because it matches from the first “, ” through the “;”.

      • #116592
        Colleen Kiefer
        Participant

        This is so awesome!! It worked. Thank you so much, Jeremy

      • #14388346
        Colleen Kiefer
        Participant

        Hi Jeremy:
        It’s me again. I’m trying to use this GREP string “(?<=,).*?(?=;)” this year on same large project—2023 edition.

        For some reason it’s not finding anything when I search.

        I’m using InDesign 2023 (18.0); still trying to apply a character style of ITALICS to anything that falls between a comma and a semi-colon. I’m using InDesign’s Find/Change, GREP tab and the formatting box at the bottom of the dialog.

        Any ideas why this isn’t working this year. It’s worked wonderfully for the past two years. Maybe I’m forgetting how to use it?? Any help would be appreciated. Thanks. so much.
        Colleen

      • #14388353
        David Blatner
        Keymaster

        I just tried it and it does work… there must be a comma followed by a space, and then some text that ends in a semicolon.

        There are times when find/change fails… for example, check the scope popup menu, and be sure it’s not looking for some specific formatting. More tips here:

        10 Find/Change Tips

    • #14388500
      Colleen Kiefer
      Participant

      Thank you, David:

      I just got it to work on some unformatted text. I think the problem might be that there are a lot of paragraph and character styles in this document that maybe were competing somehow or limiting the scope. I read the 10 Tips for Find/Change, and the Paragraph Styles seemed like the most likely culprit. Thanks for confirming that it works. I’ll try to keep the text as free of styles as possible until I’ve made the change between the , and ;. Thanks again for you help.

      Colleen

      • #14389833
        Marc Dunker
        Member

        Are you putting this in as a GREP style or using Find/Change?

        I’m lazy, so I primarily put these in GREP styles so I don’t have to go back through it later.

Viewing 2 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads