Grep help in paragraph style

Learn / Forums / General InDesign Topics / Grep help in paragraph style

Viewing 23 reply threads
  • Author
    Posts
    • #75348
      Paul White
      Member

      Hi, this is my first post and new to grep. Been using indesign for years but not made full use of this feature.

      I have received a large document which is basically a price list. Grep in my paragraph style don’t seem to be working like it should, can someone help?
      Paragraph Style: Price List
      Character Styles: Price & Additions

      The problem.

      5th – 9th \t Mon/Fri \t Weymouth \t £149 \t 1/2 Price bar noon – midnight.\n

      Price in Bold/Blue
      1/2 Price bar noon – midnight. in Red/Uppercase

      Grep Style: Apply Style: Price to text: \t\£\d+
      This is not working?

      Additions I have no idea how to set up after \t any character before the \n

    • #75349
      Masood Ahmad
      Participant

      Hi Paul, welcome to the forum. Just need to know more about your query.

      1. What exactly you want to achieve?
      2. what are these \t / \n? Are these tab symbols, line break?
      3. The style you have used in your GREP Style section “Price” is not mentioned above.
      4. How would you like your final output to look like?

      Please advise so that we can understand it better?

    • #75351
      Paul White
      Member

      What I am trying to achieve is when I apply a paragraph style to this document it automatically changes price tab and additions tab content using Grep

      I can’t add an image so difficult to explain.

      5th – 9th [TAB] Mon/Fri [TAB] Weymouth [TAB] £149 [TAB] 1/2 Price bar noon – midnight[RETURN]

      [TAB] \t
      [RETURN] \r

      1) I am looking to change the character styles of Price= £149
      2) I am looking to change the character styles of Addition= 1/2 Price bar noon – midnight

      N.B. Character styles are setup.

    • #75352
      Masood Ahmad
      Participant

      Try this:

      Apply Style: Price
      ?To Text: £\d+

      Apply Style: Price & Additions
      ?To Text: (1/2.+)
      (PS: I hope it will always be 1/2)

      Please note that you can only use character styles as a default while working on GREP Styles.

      Check this and let me know if it works

    • #75354
      Masood Ahmad
      Participant

      Or, for the next code you can also use:

      Apply Style: Price & Additions
      To Text: (?<=\d\t).+

    • #75358
      Paul White
      Member

      Masood that works brilliantly. Thank you?

      how would i go about changing any character before the 1st tab? in this case the date. would it be this?

      (?<=\t).+

      • #75361
        Masood Ahmad
        Participant

        I can’t figure out if I can specify anything called first tab. However, you can replace any character before the tab, try this:

        GREP Find/Change:
        ?Find What: .(?=\t)
        Change to: character(s) or Text of your choice

    • #75359
      Paul White
      Member

      ohh and how do you replace a character ie em dash “–” replace with a minus sign “-”

      thanks

      • #75362
        Masood Ahmad
        Participant

        Try this:

        GREP Find/Change:
        Find What: ~_
        Change to: ~=

    • #75365
      Masood Ahmad
      Participant

      Sorry paul, I put the code for the n-Dash in the Change to: field.

      If you want a hyphen, simply put a hyphen - or a nonbreaking hyphen ~~

    • #75386
      Masood Ahmad
      Participant

      Hi Paul,

      I got a better code with the suggestions of Ron for your second query:
      2) I am looking to change the character styles of Addition= 1/2 Price bar noon – midnight

      Apply Style: Price & Additions
      To Text: £\d+\t\K.+
      Note: This will work on cs5.5 and later. I test my codes on CS5, where the \K was not working, then I tried in CS6 and it works fine.

      Hope things are better now.

    • #75390
      Paul White
      Member

      Hi
      Firstly £\d+\t\K.+ doesn’t work. I am using CS6 and you have put Apply Style: Price & Additions

      Price is one style, Additions is another. but the above didn’t change anything.

      I also didn’t know the grep in paragraph styles didnt do find and replace and can only be done automatically without a manual find and replace.
      Like you mention GREP Find/Change:
      Find What: ~=
      Change to: ~~
      This worked for me. Thank you.

      was thinking how do you select for style change anything from ‘start of line’ or after \n|\r a positive lookup to the first \t (ie a line of digits and charctors no fixed length up to the 1st tab point.)

    • #75391
      Masood Ahmad
      Participant

      Something might be wrong somewhere. I have uploaded the InDesign file for your reference:

      https://www.hightail.com/download/bXBieW4ycWY1R05BSXNUQw

      Yes, you can perform Find/Change in Styles, only the character style can be applied matching the string.

      For your last part, I would suggest to go through https://creativepro.com/resources/grep
      Please feel free to post other questions as well. I would be happy to help.

    • #75392
      Paul White
      Member

      That works great, recreated it and used it on my working file. All fine here not sure why it would’t work on the original file, the file upload was a big help.

      sorry to be a pain, what grep would be ideal to manage the word weymouth for instance ie place name bold style N.B place names change per line.

      largest place name is WARNERS – CORTON HOLIDAY VILLAGE
      32 characters

      18TH – 22ND MON/FRI WARNERS – CORTON HOLIDAY VILLAGE £279 1/2 bar nightly
      18TH – 22ND MON/FRI Warners – Gunton Hall £299 £1 bar 12 noon – 8 pm nightly

      Just trying to learn more about this but your input is a great relief and very insightful.

    • #75396
      Masood Ahmad
      Participant

      I’m glad that I could help.

      What I have understood is that you want to apply a Bold character style to the place names.

      If I’m not wrong, the place name has (day/day and a tab) before and a tab after it. If this is so, then here is the code for you:

      Apply Style: BOLD
      To Text: /.+?\t\K.+?(?=\t)

      Please let me know if it is okay :)

    • #75398
      Paul White
      Member

      That works a treat… just so I know what is the \K. part of the code stand for?

    • #75399
      Masood Ahmad
      Participant

      Okay, when should I come for the treat… :)

      so here is the breakup:

      /.+?\t\K Condition one
      This will look for a slash, followed by any character, followed by a tab
      \K means Keep (same as lookbehind)

      .+?
      This is the actual string we are looking for to make it BOLD i.e. any character

      (?=\t) Condition two
      This will look for a tab just after our actual string

      Hope that helps :)

    • #75401
      Paul White
      Member

      It all helps. Does not seem so alien to me now and slowly building up some knowledge. Actually finding resources on this was difficult until now, with your help.

      I am sure I will have loads of other questions but this helps to reduce time in future projects.

      Thank you

    • #75403
      Masood Ahmad
      Participant

      Paul, It was a good discussion. I learned a lot today and I’m very happy about it.

      You can post as many questions as you want, I/we will be here to sort it out.

      Thanks you :)

    • #75502
      Paul White
      Member

      Hi Masood.

      The help you gave me last week was invaluable. However, I am having problems trying to apply similar commands to a fairly basic grep. Just wondering if I could have a little assistance?

      1. How do you find a work to apply a style to? ie ‘Free package’ anywhere within a paragraph?

      2. Apply one style to ie. ‘The Crown Hotel’ \r this is any name at the start of a paragraph before the soft return, then followed by location ‘Dorset’?
      The paragraph would look like this….

      The Crown Hotel
      Dorset

      Lorem ipsum dolor sit amet, FREE PACKAGE elit. Sed dui felis, pellentesque eget neque at, fermentum iaculis nisl. Nullam volutpat laoreet facilisis. Mauris scelerisque ex euismod posuere congue. Maecenas vehicula consectetur dictum. Nullam tempus,

      FREE PACKAGE
      Lorem ipsum dolor sit amet

    • #75503
      Paul White
      Member

      Just thought of something else whilst working on the above.

      Can you grep a find for a word ‘whitey’ and make it a styled hyperlink?

    • #75552
      Masood Ahmad
      Participant

      Hi Paul,

      I was not available for the last couple of days and I didn’t realized that there is another question hidden in this thread. If you would have started a new post with your newer question, then someone else might have answered it.

      However, here are the codes as per my understanding:
      1. How do you find a work to apply a style to? ie ‘Free package’ anywhere within a paragraph?

      Answer:
      Apply Style: YourStyle
      To Text: Free package

      2. Apply one style to ie. ‘The Crown Hotel’ \r this is any name at the start of a paragraph before the soft return, then followed by location ‘Dorset’?
      The paragraph would look like this….

      The Crown Hotel
      Dorset

      Answer:
      Apply Style: YourStyle
      To Text: (^.+\r)(?=Dorset)

      Hope these will help.

      Regarding your hyperlink question, I think that is not possible. Might be someone else could have a better idea…

    • #75654
      Paul White
      Member

      that didn’t work….!! Although

      Free Package…. appears as a sub header and within paragraph text but in upper and lower text format (f|F)ree (p|P)ackage

      The Crown Hotel
      (^.+\t\r) I had to put a tab in after the hotel name because it was applying the style to the start of every sentence with the paragraph style not just the start of the story. unless anyone knows a better way of doing this?

      The Crown Hotel (^.+\t\r)
      Dorset

      Free Package (f|F)ree (p|P)ackage

      Cant find the best way to style the Dorset.
      had thought of (?<=\r\r)
      This is the only occasion where there are 2 hard returns but I can get this to work. It will be any word/any character so I thought the positive lookbehind from the two returns would be easy…

      any ideas

    • #75689
      Masood Ahmad
      Participant

      Hi Paul, try this to apply style to the Free Package:

      Apply Style: Your Character Style
      To Text: \b(?i)free package(?-i)\b

      Regarding your second query, It seems I haven’t understood your query very well. I would suggest you to upload your InDesign file or atleast provide three-four paragraph of text to understand it better along with your query in detail. For example: what the text will look like and what you want to achieve.

      Waiting….. to help :)

    • #75707
      Paul White
      Member

      where or how do you upload a cs6 doc?

    • #75721
      Masood Ahmad
      Participant

      You can upload it to your Dropbox and share the link here or can email me at [email protected]

      By the way has the code for your “free package” (listed above) worked?

Viewing 23 reply threads
  • You must be logged in to reply to this topic.
>