Add character with GREP

Learn / Forums / General InDesign Topics / Add character with GREP

Tagged: ,

Viewing 7 reply threads
  • Author
    Posts
    • #75933

      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!

    • #75934
      Aaron Troia
      Participant

      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

    • #75935

      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!!!

    • #75938
      Masood Ahmad
      Participant

      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 :)

    • #75939
      Aaron Troia
      Participant

      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.

    • #104266

      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

    • #104267

      Try:

      F: ((\u\l+\h){2})(?=(?2))
      R: $0|

      Best,
      Michel, from FRIdNGE

    • #104268

      Finally, I prefer this one:

      F: ((\u\l+)\h(?2))\K\h(?=(?1))

      It just selects the space! …

      ;-)

      • #104278

        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.

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