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

My GREP Nightmare!

Return to Member Forum

  • Author
    Posts
    • #58297
      Simon Duckworth
      Participant

      Hi All,

      I wondered if anyone could possibly help me? I've got a GREP issue which I can't solve at all. Bascially I need to be able to change the styling on the leading numbers on a heading so I can style the rest of the line independently. I'm looking to put them in the paragraph styles for each heading, so the numbering can stay regular and the rest of the line italicised. The headings run like so:

      1.2. Mauris facilisis pretium justo ut viverra. Fusce dignissim commodo sapien, id.

      1.2.3. Mauris facilisis pretium justo ut viverra. Fusce dignissim commodo sapien, id.

      1.2.3.4. Mauris facilisis pretium justo ut viverra. Fusce dignissim commodo sapien, id.

      1.2.3.4.5. Mauris facilisis pretium justo ut viverra. Fusce dignissim commodo sapien, id.

      1.2.3.4.5.6. Mauris facilisis pretium justo ut viverra. Fusce dignissim commodo sapien, id.

      You get the idea. I've been trying to use a GREP such as ^d{5}? to find the beginning of the para, and select 5 numerals (for example), but the periods after the numbers throw it.

      Does anyone have any suggestions/better ways to do this please?

      Many thanks!

    • #58298
      David Blatner
      Keymaster

      I think this should do it:

      ^(d.)+

    • #58300

      David, you might want to allow more than 9 consecutively numbered headings:

      ^(d+.)+

      Biggedy, your GREP ^d{5}? will select 5 digits at the start of a line (although I wonder what side-effects the ? has), but GREP is extremely literal: only if there are 5 digits in a row, it will be styled. As you already noticed, 5 times a digit-then-a-period does not qualify; GREP is not for “sort of like, you know, 5 digits”.

    • #58302
      Simon Duckworth
      Participant

      A massive T H A N K Y O U to you both for putting me straight.

      As you can tell, I'm finding inplementing GREPs very difficult, although I can appreciate the benefits they bring to InDesign.

      If I may ask one more question – how would the GREP change if I were to target a specific type of header with 5 numbers and periods, for example? Would it be as simple as…

      ^(d+.){5}+

      Thanks again, I really appreciate your help.

      Biggedybong

    • #58303

      Well, you are getting there. Take small steps, that's all.

      Your GREP would work … apart from two tiny things. The '+' at the end is not necessary! After any GREP command, you can add a 'repetition' code, which may be one of ?, *, or +, or an exact number or number range, like {5} or {3,6}. (And after that you can add another ?; this indicates that the lowest possible number of repetitions ought to be taken, rather than the largest number — which is the default setting.) In this case, I think that InDesign will interpret it as “5 digits-plus-a-period”, and then repeat this as much as possible, marking all possible sets of 5, rather than what you intended, only one set of 5.

      The other thing is, you set a lower limit (the {5}) but you don't specify what ought to be next. So five digit-headings would be marked, but the first 5 of a six-digit heading as well. To prevent that, matching should stop right after the five you already have, and the easiest way is: because you don't want to find a match for a number after the 5th digit, it should match “not-a-digit” … (Obvious, really.) The code for not-a-digit is this: D, so your GREP will work like this:

      ^(d+.){5}D

      There is a tiny, tiny catch: if 5 digits (and their periods) are matched, the character right after it (the I-Am-Not-A-Digit) will also be marked, because it's 'inside' the regular expression. Now in ordinary use, like bolding or italicizing the heading number, and assuming the next character will typically be a space, it won't really matter; but if you change the heading marker to be underlined, you will see the underlining stick out into the next character. So a slightly better version is, with the help of my little friend Lookahead:

      ^(d+.){5}(?=D)

      meaning that it will find a set of 5 digits-plus-periods which must be followed by a Not-A-Digit character — the Lookahead matches, but does not mark, the text.

      (This is a Positive Lookahead; there is also a Negative Lookahead, slightly more logical in this case:

      ^(d+.){5}(?!d)

      — the same as above, only it now reads “.. which must not be followed by a digit”, which is more natural than the double negative.)

      By the way #1: use d+, rather than d! Or else it will fail (silently) on “1.2.5.6.10. “

      By the way #2: this forum eats backslashes for breakfast. Only feeding it a double breakfast makes it spit out a single one: type “\d” to get “d”. Be careful when editing your post, all double backslashes will appear as singles again.

    • #58304
      Simon Duckworth
      Participant

      @Jongware,

      Wow!

      Seriously, thank you so much for taking the time to write such a comprehensive reply – that's a fantastic help.

      There's a lot to learn with those there GREPs!

    • #58307
      David Blatner
      Keymaster

      Jongware: “you might want to allow more than 9 consecutively numbered headings”

      David: Umm… no, at that point I would send the document back to the client along with a 3-day old dead fish (which usually ensures they don't call me back).

      Biggedybong: You are right that there is much to learn. Jongware is a great help. Also check out: http:/indesignsecrets.com/grep for more resources, including books and videos on the subject.

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