Grep help in paragraph style
Learn / Forums / General InDesign Topics / Grep help in paragraph style
Tagged: GREP paragraph styles
- This topic has 27 replies, 3 voices, and was last updated 8 years, 10 months ago by Masood Ahmad.
-
AuthorPosts
-
-
May 14, 2015 at 4:38 am #75348Paul WhiteMember
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 & AdditionsThe 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/UppercaseGrep 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
-
May 14, 2015 at 4:52 am #75349Masood AhmadParticipant
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?
-
May 14, 2015 at 5:06 am #75351Paul WhiteMember
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] \r1) 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 – midnightN.B. Character styles are setup.
-
May 14, 2015 at 5:41 am #75352Masood AhmadParticipant
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
-
May 14, 2015 at 5:53 am #75354Masood AhmadParticipant
Or, for the next code you can also use:
Apply Style:
Price & Additions
To Text:(?<=\d\t).+
-
May 14, 2015 at 6:19 am #75358Paul WhiteMember
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).+
-
May 14, 2015 at 6:48 am #75361Masood AhmadParticipant
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
-
-
May 14, 2015 at 6:36 am #75359Paul WhiteMember
ohh and how do you replace a character ie em dash “–” replace with a minus sign “-”
thanks
-
May 14, 2015 at 6:53 am #75362Masood AhmadParticipant
Try this:
GREP Find/Change:
Find What:~_
Change to:~=
-
-
May 14, 2015 at 7:48 am #75365Masood AhmadParticipant
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~~
-
May 15, 2015 at 2:17 am #75386Masood AhmadParticipant
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 – midnightApply 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.
-
May 15, 2015 at 4:15 am #75390Paul WhiteMember
Hi
Firstly £\d+\t\K.+ doesn’t work. I am using CS6 and you have put Apply Style: Price & AdditionsPrice 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.)
-
May 15, 2015 at 4:41 am #75391Masood AhmadParticipant
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. -
May 15, 2015 at 5:48 am #75392Paul WhiteMember
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 characters18TH – 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 nightlyJust trying to learn more about this but your input is a great relief and very insightful.
-
May 15, 2015 at 6:26 am #75396Masood AhmadParticipant
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 :)
-
May 15, 2015 at 7:42 am #75398Paul WhiteMember
That works a treat… just so I know what is the \K. part of the code stand for?
-
May 15, 2015 at 8:38 am #75400David BlatnerKeymaster
Paul: Take a look at Peter Kahrel’s article on \K in this issue of InDesign Magazine: https://creativepro.com/issues/issue-73-food-issue
-
May 15, 2015 at 9:37 am #75402Masood AhmadParticipant
Unfortunately, I can’t see it… :)
-
-
May 15, 2015 at 7:52 am #75399Masood AhmadParticipant
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 stringHope that helps :)
-
May 15, 2015 at 8:57 am #75401Paul WhiteMember
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
-
May 15, 2015 at 9:39 am #75403Masood AhmadParticipant
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 :)
-
May 20, 2015 at 6:15 am #75502Paul WhiteMember
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
DorsetLorem 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 -
May 20, 2015 at 6:17 am #75503Paul WhiteMember
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?
-
May 22, 2015 at 6:08 am #75552Masood AhmadParticipant
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
DorsetAnswer:
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…
-
May 26, 2015 at 6:46 am #75654Paul WhiteMember
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)
DorsetFree 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
-
May 27, 2015 at 5:48 am #75689Masood AhmadParticipant
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 :)
-
May 28, 2015 at 8:19 am #75707Paul WhiteMember
where or how do you upload a cs6 doc?
-
May 29, 2015 at 7:37 am #75721Masood AhmadParticipant
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?
-
-
AuthorPosts
- You must be logged in to reply to this topic.