Skip navigation
Currently Being Moderated

Apply grep style only once

Jul 31, 2012 10:14 AM

I can't get my brain around what is probably a very simple problem: I want a paragraph style that applies boldfacing to any character up to an including the first colon in a paragraph. If I used  a nested style "through 1 :" the whole graf is bold if there is no colon. So that's out.

 

A grep style ".+: " seems to work in most cases, but if there's a second colon, the boldfacing is extended to that point. What I think I want is a grep style that works "zero or 1 times" but I cannot figure out how to use the ? to make that happen.

 
Replies
  • Currently Being Moderated
    Jul 31, 2012 10:25 AM   in reply to RobertKyle

    @Robert – try this one:

     

    ^.+?:+?
    

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 11:25 AM   in reply to RobertKyle

    @Robert – I did a little trial and error and we can reduce the expression to:

     

    ^.+?:
    

     

    It's the "not greedy" version of:

     

    ^.+
    

     

    followed by the colon.

     

    My first attempt added a not needed part I did not delete after experimenting.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 1:19 PM   in reply to RobertKyle

    A-ha. Now that is not possible with GREP styles -- they are part of a paragraph style, and strictly limited to text inside each paragraph. No peeking out of it either way. Single-line and multi-line modifiers do not work, and neither does fiddling with \r anywhere inside a GREP style.

     

    You have to create another paragraph style containing this GREP only, and apply it to your first paragraph.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 12:33 AM   in reply to [Jongware]

    @Jongware – I think Robert wants to limit the GREP style to the first line of a paragraph.

    But unfortunately GREP in InDesign does not know about line endings.

     

    In scripting we could do something like what he wants, but comes with some obstacles, because the GREP will apply a character style, that will probably change the line ending. A very dynamic situation…

     

    Example 1

     

    Basic situation:

     

    This is my text here comes the colon: and

    here another one: that Robert don't like

    to take into account using the GREP style.

     

    Formatted after  the GREP style is applied:

     

    This is my text here comes the colon: and

    here another one: that Robert don't like

    to take into account using the GREP style.

     

    As I understand it, in case that the first colon will leave line one, only the first line should be formatted like this:

    (Case 1)

     

    This is my text here comes the first

    colon: and here another one: that

    Robert don't like to take into account

    using the GREP style.

     

    Or should it be, that the style should only be applied, if it's in the first line?
    (Case 2):

     

    This is my text here comes the first

    colon: and here another one: that

    Robert don't like to take into account

    using the GREP style.

     

    But what, if the colon in the basic case is at the end of line 1 and will be shifted to line 2 after formatting?

    What should happen then?

     

    That is simply not possible to format automatically (dynamically) using GREP styles in InDesign.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 3:40 AM   in reply to Laubender

    Uwe, I don't see that at all in the original post. He seemed quite clear to me that he wanted to apply the style up the first colon, no matter where, and not beyond, and that the style should only be applied IF there is a colon, ruling out a regular nested style. The only reference I see to anything like the first line is the beginning of paragraph mark.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 4:29 AM   in reply to Peter Spier

    @Peter – I assumed this because of:

     

    So now I'm wondering how to limit the grep to the first line

     

    in #4.

     

    I could be totally wrong…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 4:31 AM   in reply to Laubender

    Ah yes, missed that. It is ambiguous, isn't it?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 4:47 AM   in reply to Peter Spier

    Yes.

     

    If a "Nested Line Style" could overwrite a "GREP Style", we could manage that, but "unfortunately" that isn't…

     

    Not working example:

     

    GREP Style:

    Apply Style: "BoldFont_CharacterStyle"

    To Text: ^.+?:

     

    Nested Line Styles:

    [None] for 1 lines

    "RegularFont_CharacterStyle" for 999 lines

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 4:59 AM   in reply to Laubender

    suppose you approach it the other way. Apply the line style to the first line and then apply a GREP style to UNdo it after the first colon with a lookbehind? Not quite sure how to make that work so the line style is removed if there is no colon... Perhaps a second GREP style that looks for the string at the beginning and checks for a colon, but I'm not sure how to prevent that from being applied if the colon is found.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points