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

Indesign grep – Applying character style to a letter on the third tab

Tagged: ,

Return to Member Forum

  • Author
    Posts
    • #116957
      Andrew C
      Member

      Hello All

      I hope you are well. I have recently started using grep and in a lot of cases it has saved a lot of time. Im currently working on a large document and I need to apply a character style to a particular letter on the third tab. I have been really struggling, having ploughed through countless posts and tutorials I can’t seem to get my head around this. I have used ^. to get me to the third tab but it only seems to find and highlight 3 empty tabs I’m thinking I need to use a positive lookback, followed by a character search but I don’t really understand how it works. Ive tried multiple combinations with no luck.

      To reiterate,I need to apply a character style to a ‘letter’ on the third tab so in this instance it would be the letter ‘B’

      D3 1,25 Vitamin D B 5-8 days £00.00

      Any help would be greatly appreciated, many thanks in advance.

    • #116959
      Jeremy Howard
      Participant

      Hey Andrew,

      GREP can be a bit frustrating when you first start diving into it but I think it’s great that you’re giving it a go.

      The issue with your grep is that you are stating that the style should be applied to the beginning fo the paragraph (^) then one character (.) and then two consecutive tabs (). What I would use for something like this is “\K” which causes the GREP string to ignore everything matched before it.

      Here is the GREP string that I used to make this work:
      .+.+\K.(?=)

      This expression is stating that it should match, but not style, everything before the \K (.+.+)

      The first part, (.+.+) says: one or more characters (.+) one tab character () one or more characters (.+) one tab character () IGNORE the matched stuff before here (\K) one character (.) with a positive lookahead to a tab ((?=))

    • #116960
      Andrew C
      Member

      Hello Jeremy

      Thank you so much for the swift response and taking the time to respond.

      Your grep expression is perfect and theres no way i would have reached that conclusion on my own, i’m now able to select the ‘B’ and change it. However there are instances in the third tab when there are other letters and in some cases words (as shown below – FCRU, PCR Swabs x2, B, A, H )

      Would it be possible to isolate the grep to look for a particular letter or word in the third tab ignoring everything else? For example if i wanted to apply a character style to just the letter B or A or H in the third tab, the words are less important but would be useful.

      SH10 Advanced Screen for MSM FCRU, PCR Swabs x 2, B 4 hours £00.00
      ACTB Acetone – Blood A or H  2 weeks £00.00

    • #116962
      Jeremy Howard
      Participant

      You could do it with this:

      .+.+\K.*?(?=(?!£))

      But that assumes that there will always be a “£” symbol after the final tab character in the line…

    • #116997
      Andrew C
      Member

      Hi Jeremy im back at work. Hope you had a pleasant weekend, thanks for getting back to me. You are correct there is always a ‘£’ in the 5th final tab

      I have tried your grep expression and assumed that perhaps the asterisk was a wild card and changed it to ‘H’. . i also messed about with your grep at regxr changing variables but no joy.

      Perhaps my example of tabs aren’t really showing well when i paste them into this post message, using the above as an example i will annotate below if it helps?

      1ST TAB: SH10
      2ND TAB: Advanced Screen for MSM
      3RD TAB: FCRU, PCR Swabs x 2, B (need to change variables in this tab, grep required for this line)
      4TH TAB: 4 hours (changes sometimes hours, sometimes days)
      5TH TAB: £00.00 (always price at the end typically no more than 2 or 3 decimal points i.e £21.00 or £176.00)

      Im not sure i fully understand how to implement this grep, just when i seem to think i have some understanding i realise i don’t. Apologies if i’ve over engineered this post.

    • #116998
      Andrew C
      Member

      Hi again Jeremy

      I think i got it, thank you very much!!! I placed the character i am searching for after the * replacing the ?

      I need to practice using grep it has such great utility, i’m embarrassed to say i have been using indesign for over 8 years and had never needed it before. It reminds me of setting up automations in ifttt.

      But thanks again you have saved me so much time. Have a great day!

    • #117001
      Jeremy Howard
      Participant

      Hello Andrew,

      I think that things are getting confused because you are referring to the data sets as “tabs” when we are trying to match on literal tab characters to figure out where to format text. Perhaps it would help if I explained what my GREP expression is doing.

      Here is the entire expression:
      .+.+\K.*?(?=(?!£))

      Let’s break it down into it’s different pieces so that we can better understand what is happening. Here is part 1:
      .+.+\K

      .+ this is the expression for one or more characters (any character is covered by this)

      – this is a tab character

      .+ one or more characters

      tab character

      \K Ignores everything matched up until this point

      so, at this point, the GREP expression is stating that it should match one or more characters TAB one or more characters TAB and then, with the “\K” we are stating that we do not want to apply any character styling to those matches.

      Here is part 2:
      .*?

      .*? this is the expression for zero or more characters. I used this, rather than the “.+” because doing it this way is “non-greedy” meaning that it will match only what it needs to in order to meet the conditions of our statement. Conversely, “.+” is “greedy” – it will always try to match as much as it possibly can.

      Part 3 is where things begin to get tricky:
      (?=(?!£))

      What we have here is a nested look-around (a negative look-ahead nested within a positive look-ahead). We are essentially saying that we want to look ahead to a tab character () that is not followed by “£”.

      Let’s see how all of this matches up to the example that you gave:

      View post on imgur.com

    • #117003
      Andrew C
      Member

      Hi Jeremy

      Wow that diagram is clever way of illustrating the grep and is very helpful.

      I must have got lucky then because when searching for ‘A’ i typed: .+.+\K.*A(?=(?!£)) i placed the A after the asterisk and it seemed to work
      but looking at your breakdown it should be: .+.+\KA(?=(?!£))

      There are sometimes commas, parentheses in the third tab location for example when searching for A and the third tab can sometimes look like this:

      A, B, B, G
      B [7, 35]
      A, A (Frozen) 

      Therefore the grep search skips it but ill try and figure out how to ignore commas etc as i think i’ve asked much of you already. I think my main mental hurdle is completely understanding the various uses of positive and negative lookahead and behind and the sequencing of the expressions but your diagram has helped me get somewhat closer….at times its been like staring at a car engine and having no clue :)

      This is something i really want to grips with but unfortunately i don’t have one of those minds that are proficient with formulaic equations so its going to be alot of trial error, i have to admit i had all but given up before your help. I was preparing myself to tediously manually copy and paste each entry.

      Thanks for your time and patience Jeremy its greatly appreciated.

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