Add character with GREP
Learn / Forums / General InDesign Topics / Add character with GREP
- This topic has 8 replies, 5 voices, and was last updated 5 years, 10 months ago by Reiner Van Wonterghem.
-
AuthorPosts
-
-
June 10, 2015 at 4:10 pm #75933Andrea VelazquezMember
Hello, I am kinda new with GREP, hope someone here can help me :)
I want to add a character instead of replace it with another using FIND and REPLACE > GREP
I need to do it at the beginning of paragraphs…. I found that ^ finds the beginning of the paragraph, but how can I add something?
I found out how to replace the first character with another, but I don’t want to lose any character…What I need to do is to add double quotes at the beginning and end of certain paragraphs, that are using an specific paragraph style…
Is possible to do this with GREP? Is there any other way? Maybe a script?
Thanks!
-
June 10, 2015 at 4:26 pm #75934Aaron TroiaParticipant
Andrea,
that’s totally possible with GREP, try this. I’m using a capturing groups which is represented by the parenthesis which says “group this content” and I can later call that group in the replace field by referring to it with a back reference which is a GREP variable which always starts with the dollar sign and number (1-9). So below I’m capturing all the text in the paragraph, then adding the double quotes to either side of the back reference.
Find:
^(.+?)$
Replace:~{$1~}
Let me know if that works for you and/or if it needs tweaking
-
June 10, 2015 at 4:30 pm #75935Andrea VelazquezMember
Oh Great!!! it works!!!!!
I don’t know how you got there but it works!! Thanks so much!!
It seems I need to learn more about GREP, any recommendation of where to learn more?
Thanks Thanks Thanks!!!
-
June 10, 2015 at 9:25 pm #75938Masood AhmadParticipant
You can explore the GREP section here itself. Just search for “grep”, and you’ll get a page full of references and other useful links to start with.
Best of luck :)
-
June 10, 2015 at 9:32 pm #75939Aaron TroiaParticipant
No problem, I’m glad that worked!
I started learning Regex with the O’Reilly GREP Pocket Reference (https://shop.oreilly.com/product/9780596153618.do) to learn the basics, then I moved on to O’Reilly’s Mastering Regular Expressions (https://shop.oreilly.com/product/9780596528126.do) which explains more advanced features like capture groups, call backs, lookahead/lookbehind assertions and more, which really take your GREP to the next level. I would totally recommend both books for learning GREP. you might also look into the InDesign plugin WhatTheGrep by Jongware (https://www.jongware.com/idgrephelp.html) which will break down a Regular Expression and explain everything that’s going on. I could even send you some GREP searches that I use almost daily in InDesign and you could then use that script to break it down and see what each piece is doing. Also look up the InDesign metacharacters list (there are characters for double/single quotes, non-breaking spaces, even clipboard content) and print out a copy, those are invaluable to doing GREP in InDesign.
Anyway, I’m glad that helped, and good luck with GREP it’s a great way to up your InDesign skills!! Let me know if you have any other questions.
-
June 9, 2018 at 4:49 am #104266Reiner Van WonterghemMember
Hello
I would also like to add the character “|” to a list of names.
Andy Johnson Johnnie Walker -> Should become: Andy Johnson | Johnnie Walker
Preferably that Indesign inserts the character after each 2 words.
Is this possible using GREP or some other method?Thanks a lot in advance,
Reiner -
June 9, 2018 at 5:22 am #104267Michel Allio for FRIdNGEParticipant
Try:
F: ((\u\l+\h){2})(?=(?2))
R: $0|Best,
Michel, from FRIdNGE -
June 9, 2018 at 6:03 am #104268Michel Allio for FRIdNGEParticipant
Finally, I prefer this one:
F: ((\u\l+)\h(?2))\K\h(?=(?1))
It just selects the space! …
;-)
-
June 11, 2018 at 2:27 am #104278Reiner Van WonterghemMember
Hi Michel
Thanks for the fast reply.
I’m kind of new with Indesign, could you please sum up the different steps or refer to a post?Thanks a lot in advance.
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.