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, if it could only go backwards

Return to Member Forum

  • Author
    Posts
    • #53886
      Anonymous
      Inactive

      I've been working on a lot of grep for my company's catalog style sheets lately and have come up with a problem that i don't think can be fixed, but I'm gonna put it up here and see if you folks can solve it.

      In one of my paragraph styles, you'll frequently see text like:

      Color: (01) black (handbag only), (02)white, (03), blue (coat only)

      with the (xx only) blocks italicized. I understand that if they said (only black), i could easily write an expression:

      (only.+?) and apply an italicized character style to it, but its not possible for this to look in reverse:

      (.+?only) will find the first “(” in the paragraph and go all the way to the first instance of “only)”

      can anyone else think of a different way to write this style so that it would work? if only you could make GREP start at the end of a specific expression and go to the front.

    • #53888

      Hello,

      With you example, this regex works : ([^)]+only)

      It finds (handbag only) and (coat only)

      Laurent

    • #53890

      (In this case I'd avoid having italicized and regular parentheses right next to eachother. Changing Laurent's expression to

      (?<=()[^)]+only(?=))

      will do that.)

    • #53891
      Anonymous
      Inactive

      @jongware

      (?<=()[^)]+only(?=))

      Ok I understand (?<=() That's a positive look behind (?<=) and ( is a a parenthesis

      Just wondering what the following does?

      • [^)]+

      I know that (?=)) = postive lookahead and ) is a closed parenthesis

      How does this GREP work?

    • #53892

      [ .. ] group definition

      [^ .. ] not group definition — anything except what's inbetween the brackets

      [^)] anything but a closing parenthesis

      [^)]+ lots of characters, stop on the first encountered closing parenthesis

      … but not tested … perhaps the ) needs a backslash? (I didn't think so, because you cannot define groups inside an inclusion group.)

    • #53893
      Anonymous
      Inactive

      Thanks Jongware – that is indeed very clever. Gotta remember that one.

    • #53894

      Hi,

      The parenthesis, as litteral character, inside a group [ ] or negative group [^ ] doesn't need blackslash. Same think for [ { } + . ? * | ^ $

      @ Jongware : thanks for explanations, it is difficult for me to explain in english.

      In the regex, you can also use [^(]+

      Laurent

    • #53895
      Anonymous
      Inactive

      Wow, you guys are fast. Yeah, with Jongware's explanation it seems to make sense. Just to clarify, i could do the same for any sentence ending in “may not specify” by using:

      (?<=.)[^.]+may not specify.

      Right? Big help guys, thanks

      And yes I would agree with jongware on not italicizing the () characters, but sadly the choice is not mine. Its a 20+yo catalog and they're not too keen on changing the style standards for the sake of good design standards :(

      edited grep code so its actually correct, left out the lookbehind oops

    • #53900
      valedot
      Member

      Hello to all from Italy, are an Italian ignorant, I know the English language …
      might work in your opinion this solution?

      ([(]only)s?(w+[)])|([(]w+)s?(only[)])

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