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 with hyphens with various numbers

Return to Member Forum

  • Author
    Posts
    • #55151
      Cindy Kelley
      Participant

      Hi,

      I am so wanting to learn GREP but finding it a slow learning process for me. I am hoping at some point things will just “click” and I will become a master :)

      Until then, I need some help

      I am working on a photography book that lists various lens used by the photographer. These should be listed, in italics, as “24-70mm” but at times they are listed “24 – 105mm” or “70-200 mm”

      Can anyone help me out with the expression to solve this problem with GREP?

      thanks!

      cindy in indy

    • #55153
      Anonymous
      Inactive

      (sorry for all the edits, i can't get a backslash (reverse solidus) to show up in the text, even when I put in the html code… everywhere you see the letter “d+” insert backslash before it)

      Ok this should work

      Find

      (d+).+?(d+).?mm

      Change To

      $1-$2mm

      Explanation:

      d+ is any amount of digits in a row

      . is to find any character, and

      +? is to find the shortest match

      d+ finds any amount of digits in a row again

      .? will find any character zero or once only, and

      mm is simply the text you have “mm”

      (d+).+?(d+).?mm

      Anything that is in brackets (parenthesis) are marked as “found”

      $1 and $2 are to use the “found” text and insert it

      $1-$2 is to put a hyphen between the found text

      and mm at the end is to mark it as mm

      So find

      (d+).+?(d+).?mm

      Change to

      $1-$2mm

      Should find any instance of digits with any characters inbetween them once it's followed by mm.

    • #55156
      erickp
      Member

      Sorry but I don't mean to hi-jack this post but I have a question about a GREP expression.

      How do I specifiy to change any number that is followed by double quote to that same number but with double straight quote?

      I have an issue of imported text that contains inches and foot quotes but they come in as normal quotes, not the proper straight quotes. Is there a GREP expression to change and replace all of these? Any help is appreciated. Thank you!

      ~Erick

    • #55157
      Anonymous
      Inactive

      <backslash> = reverse solidus character

      Find

      (<backslash>d+)~}

      Change

      $1~”

    • #55158

      (Erick, why not simply create a new thread?)

      With lookbehind, search for:

      (?<=d)~}

      replace with

      ~”

    • #55159
      Cindy Kelley
      Participant

      thank you so much. your explanation of what each expression defines is very helpful.

      Although your solution worked for what I requested (I did put in the backslashes), I realize now that I didn't give you enough information.

      I am wanting to take the text:

      Figure 1-1: Photo was taken with a Canon EOS 1D Mark III Camera, 70 – 200 mm lens at 145mm, 1/320 sec, f/4.5 and ISO 200, in manual exposure mode.

      or

      Figure 1-1: Photo was taken with a Canon EOS 1D Mark III Camera, 70 – 200 mm lens at 145mm, 1/320 sec, f/4.5 and ISO 200, in manual exposure mode.

      and convert it to

      Figure 1-1: Photo was taken with a Canon EOS 1D Mark III Camera, 70–200mm lens at 145mm, 1/320 sec, f/4.5 and ISO 200, in manual exposure mode.

      With your solution, I was getting all instances of any number with a mm following the number and not necessarily containing a hyphen or it was finding the numbers following the word Figure (i.e. Figure 1-1:)

      I tried messing around with it myself some but I ended up getting 70 – —2mm :)



    • #55160
      erickp
      Member

      @Jongware: Thanks for the expression. Now I get it. Still trying to make sense of it but I'll get it.

      I didn't want to start yet another GREP thread. Perhaps I should have but I didn't see any harm in asking within this thread. My apologies if it's out of line.

      ~Erick

    • #55162
      Anonymous
      Inactive

      Try this

      (d+)…(d+).?mm

      and the same Change to as before

      Perhaps that works

      (backslashes before the d again)

    • #55163

      Erick, no harm done, except it might get hard to have four people (five now) speaking through eachother on not-too related topics …

      Yikes, Eugene! That'll eat the middle digits right out of “12-34 mm”! Let's see. “24 – 105mm” or “70-200 mm” to “70-200mm”. Digits, some optional spaces, and a hyphen. Well, you were on the right track, but your previous efforts used the 'any' character, removing it as-you-went, no matter what it was. All it takes is a precise copy of the format, with question marks making the spaces optional:

      (d) ?- ?(d+) ?mm

      — replacing with

      $1-$2mm

      I prefer to use as much lookbehind and lookahead as possible, as (I think) it's faster to change as less as possible, but here I might get a bit less obvious:

      (?<=d) ?- ?(d+) ?(?=mm)

      — replacing with

      -$1

    • #55165
      Cindy Kelley
      Participant

      Eugene,

      PERFECT! Thank you! This is going to save me a lot of time in edits.

      And your detailed explanation helps me get one step closer to learning this stuff myself.

      thanks again,

      cindy in indy

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