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 Styles – Is this possible?

Return to Member Forum

  • Author
    Posts
    • #58456
      jimmykup
      Member

      Hi everyone,

      I was wondering if anyone here is really good with GREP Styles? I have something I want to do, but I'm not 100% positive it's do-able with GREP.

      I'd like to have certain characters within my paragraph set to a specific character style. The characters I want to affect are always the first characters in their line. And I want the modification to end after a colon or hyphen. For example:

      BUNDLED WITH: AMX Inspired Xpress Software

      would become

      BUNDLED WITH: AMX Inspired Xpress Software

      or..

      BUNDLED WITH – AMX Inspired Xpress Software

      would become

      BUNDLED WITH – AMX Inspired Xpress Software

      Is this possible with GREP styles?

    • #58458
      David Blatner
      Keymaster

      You could just use nested styles, which would be easier. When making the nested style, click on the word “Words” (which gives you a popup menu of options, such as Sentences, Characters, etc.). Instead of choosing from the menu, type : – (colon, hyphen) or use em dashes or whatever. The character style will span “up to” or “through” (depending on what you choose) whichever character it comes to first.

      That is, if you type .,! then it'll extend to the first period, comma, or exclamation point.

    • #58459

      (FYI, 'cause David's solution is easier ;) ) Using GREP styles, you would use this:

      ^.+?[-:]

      or, if this 'hyphen' is actually an en-dash as in your post, replace – with the GREP code for an en:

      ^.+?[~=:]

      It's quite simple — for a GREP match, that is. ^ is “Start of Paragraph” (and — ugh! — also Start of a line after a soft line break), .+? is “any character, as least as possible (indicated by the question mark; without, it'd be “as often as possible”), and the […] stuff is a list of “one of the characters in this list”. Note: most “special” characters inside an OR-list loose their magic properties — a period or question mark is just that — but a few oddballs have to be escaped to work. If you don't escape the single hyphen, it could be interpreted as a character range instead (as in “a-z”), and you will be wondering forever what you did wrong.

    • #58485
      jimmykup
      Member

      Thanks guys! The nested styles worked perfectly.

    • #58497

      Just for interest, the difference between a GREP style as described by Jongware and a nested style is the behaviour when the character you've assigned to end the style isn't present in the paragraph. With a nested style, the entire paragraph will appear with the chosen character style, because it styles everything until it reaches the end character – and if it doesn't reach it, it continues styling right up to the end of the paragraph. With a GREP style, nothing in the paragraph will be put into the character style, because the search pattern doesn't match anything. So whether you choose a GREP or a nested style depends on which of these two behaviours you want.

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