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 Expression to find specific range of characters?

Return to Member Forum

  • Author
    Posts
    • #55888
      James Fritz
      Member

      I am currently working on a catalog with a lot parts and there is limited space for characters.

      The catalog currently has a part number followed by a tab, then the product name, another tab, then the size.

      example: 132756 [tab] RTD ULTRAMET BANA CRM [tab] 12/17OZ

      The problem is that when the product name gets too long the entire line no longer fits. The client does not want to change fonts and the part number and size can't be changed. Don't even think cutting the text.

      Ideally the solution that that I trying to achieve is to apply a character style with -5 tracking and a 95% horizontal scale to the product name after the first tab in that paragraph once there are too many characters for the product name (lets say 25).

      What I was thinking would be possible with GREP (what isn't possible with GREP:) would be to search for the patten:

      Tab (followed by) 25 or more characters (followed by) tab.

      To add another wrinkle, it would be even more interesting if it was possible to set it up so that if that character count was over 30, a different character style was applied that applied even stronger negative tracking and more horizontal scale.

      I think this is possible in GREP (someone at the last InDesign Conference talked to me about it).

      Thanks again for whoever happens to read this. Maybe this will be fodder for a new blog post:)

    • #55889
      Anonymous
      Inactive

      How about this

      (?<=[^d{6}]t)(.{25,30})(?=t)

      That will find a string of any characters inbetween the first 6 digits and the two tabs

      The amount of characters it finds is between 25 and 30

      In your paragraph style – include a GREP styles – then add new GREP styles for 25 to 30, 30 – 35, 35 – 40 etc.

      And create a character style for each one which gives it an increased negative value for the tracking

    • #55890
      Anonymous
      Inactive

      If you think you'll have more than digits at the start then put in

      1, 100 at the very start in (?<=[^d{1,100}]t)

      which will find and ignore any amount of digits from 1 to 100

      i.e. if you have 13275679879 RTD ULTRAMET BANA CRM AFSA 12/17OZ

    • #55891
      Anonymous
      Inactive

      I don't know what's going on with my original formula there but it's not working now?

      I've rewritten it to this

      (?<=[^d{1,100}]t).{20,25}(?=t)

      Which is working for me – perhaps copying and pasting doesn't work from this forum?

      Anyway, all you have to do is adjust the {20,25} and generate new greps styles for 25,30 characters; 30,35 and so on

      Seems to be working for me

    • #55893
      James Fritz
      Member

      Thanks for the help! I will have to try it out tomorrow at work.

      Eugene, you are a gentleman and a scolar.

    • #55896

      Our scholarly gent seems to have overseen something, though.

      (?<=[^d{1,100}]t).{20,25}(?=t)

      A variable number of elements in the look behind does not work. It simply doesn't do anything (perhaps the GREP returns an error message, but Adobe — infinite wisdom and all — decided to not pass those through to the user, leaving him to wonder why nothing happens).

      Asides, everything inside the square brackets is put inside an OR-group, and the caron at the start inverts it to a NOT-group. I'm guessing it only appears to be working: it scans for a single character not (decimal or { or 1 or comma or 0 or }).

      The most reliable check you can get, for a minimum number of preceding digits n (here 4), would be

      (?<=d{4}t)[^t]{25,30}(?=t)

    • #55898
      Anonymous
      Inactive

      Why 4?

      Sorry Jongware – I think there's some code missing from your one there, can't get it to work?

      I'm having success with this too

      (?<=dt).{20,25}(?=t )

      It will only find characters between 20 and 25 characters

      So in the GREP styles for the Paragraph Style you'd have the one above linked to a character style

      Then create a new grep style of

      (?<=dt).{26,30}(?=t )

      Which will only affect the string of characters of 26 to 30 characters

      And so on

    • #55899

      Why 4?

      Erm. Why not? :-) James' example shows 6 digits, and if it's always exactly that, safest way would be to use d{6} — if only to prevent reacting to a line that happens to end with a single digit.

      My GREP does work on James' example … (on copying you might accidentally have picked up a stray space or hard return).

      I would advise not to use the any-character wildcard in .{26,30}, though. If there is a stray tab after the last item in his list, it will pick up the tab in between and the text thereafter as well. Use to [^t]{26,30} prevent this, as it will always limit the style to any text between two tabs.

    • #55900
      Anonymous
      Inactive

      Hmmm… yeh I see what you mean.

      I didn't want to use the “.” in the GREP, but other things weren't working like “w” and “[lu]”

      Didn't seem to work?

    • #55901

      Neither w+ nor [lu]+ include the spaces between those words …

      Throwing in an s would even be worse :-D It would add space, but also tabs and even the hard return at the end.

      (FYI: I think w generally equals to [dlu] — it includes digits but excludes the hyphen, which, for example, makes it worthless when looking for proper names.)

      Edit Note: if posting replaces double backslashes with single ones, Edit Post ought to do the same in reverse! As it is, posting replaces two backslashes with one, edit posting replaces one backslash with zero. I dare not try what happens when you try to edit again. I don't think Einstein predicted what would happen with negative numbers of backslashes.

    • #55902
      Anonymous
      Inactive

      I wonder if this forum could be fixed so that didn't happen LOL, oh dear.

      Well I hope James gets what he needs from all this.

    • #55909
      James Fritz
      Member

      Thank you both so much. I ended up using

      (?<=dt).{25,30}(?=t) which worked out great.

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