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 Style question

Return to Member Forum

  • Author
    Posts
    • #61638
      troycole
      Member

      I'd love some input on what I think is a very basic GREP style application.

      I'm working on a template that will have a good deal measurements including squared or cubed measurements (i.e., cm2, m3, and km2).

      So I thought that it would be simple to create a “SuperScript” character style, then apply a GREP style to the paragraph style that had a positive look behind for: digit, space, either cm, m, or km followed by a digit that would have the SuperScript character style attached. I was wrong! I can get parts of it to apply, but it's not applying in all instances and sometimes as I was trouble shooting using a string of distances separated by commas it would end up applying to a single digit of the number being squared rather than on the distance itself (e.g., 35 km2) [ sigh… ]

      The sample text I've been using to try and work this out with is: 15 m3, 25 cm2, 35 km2

      The most current itteration of my GREP query is:

      (?<=(backslash)d (cm|m|km))(backslash)d

      Note: backslash before “d” kept disappearing when I posted so I've simply put it above in brackets.

      This works as expected but will not apply the superscript to the meter measurment resulting in the following: 15 m3, 25 cm2, 35 km2

      Any input would be appreciated.

      Troy

    • #61641

      Lots of ways to skin this particular kitten. For example, this very short one may be all that's needed:

      (?<=m)d

      – it works on all of your examples :)

      But I can see where you are heading for, you only want to superscript the digit for [digit][space][measurement][²³]. In that case you were very close indeed, but the only point of failure is this:

      You cannot use lookbehind strings of variable length.

      So that's why your (cm|m|km) doesn't work — this string may be either 2 or 3 characters long. The workaround trick is to use | to separate two lookbehinds, and whatever matches first will work:

      ((?<=d [kc]m)|(?<=d m))db

      I added a b “Word break” at the end to ensure no digit or letter should follow the superscript number.


      The trick to post a single backslash is to insert two of 'em \ when posting. If you edit your post, they will be reverted to a single backslash again so then you have to hunt through your text, \doubling\ all of them again :( (Edit: I just noticed a typo, of all things right smack in the middle of my “good” GREP, so I had ta do just that! :p )

    • #61662
      troycole
      Member

      Hey Jongware,

      Thank you for the input. It's funny, just when you think you're getting a wee bit of a handle on GREP you get smacked with something like “you cannot use lookbehind strings of variable length”. I was actually using your “what the GREP” script to try and figure it out, but was still left scratching my head.

      Really appreciate the input (on both the GREP as well as getting backslashes () to show up!

      Cheers!

    • #61663

      What The GREP doesn't catch this one? Hmmm … I'll have to look into adding this then (well, some day). This is exactly one of those things that mysteriously may make a GREP not work.

    • #61699

      Those poor kittens!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Forum Ads