9 Replies Latest reply on Jun 16, 2011 2:50 AM by kmc27

    Want to Insert Text at Beginning of a Paragraph Using GREP

    kmc27 Level 1

      I'd like to find the beginning of a paragraph and insert a text (that uses a specific character style) into that paragraph. Below is how I've set up the find/change:


      It almost works. The phrase "SECOND ITEM IS FREE!" is inserted at the beginning of the paragraph, which is what I want. But the first letter of the word that was originally at the beginning of the paragraph picks up the character style used on the inserted text. How do I insert the text without changing the character style of the existing text?

       

      Thanks in advance for any ideas on this

       

      grep_insert_text.jpg

        • 1. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
          Peter Spier Most Valuable Participant (Moderator)

          How about instead of applying a character style in the GREP, apply a paragraph style. In the paragraph style, add your character style as a nested style through one !.

          • 2. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
            [Jongware] Most Valuable Participant

            (Short) Can't be done.

             

            (Long) Well, it can, but not in a single replace. You'd have to first insert the text, then assign the correct character style.

             

            (Slightly longer) You are physically re-inserting that final character, and so it will get that character style assigned. The usual way of finding-but-not-marking is to use a positive lookahead; but that doesn't work, because you would end up with two locations (the caret and the lookahead), and InDesign's particular implementation of GREP does not allow that. (Or rather -- irritatingly -- sometimes it seems to work if you press the Find button, but then a Change All is not going to work.)

            So that's why you have to insert at least one character in the Find What, and re-insert it in the Replace With fields.

            • 3. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
              Peter Spier Most Valuable Participant (Moderator)

              [Jongware] wrote:

               

              (Short) Can't be done.

               

              (Long) Well, it can, but not in a single replace. You'd have to first insert the text, then assign the correct character style.


              I usually think your solutions to stuff like this are better than mine, but in tis case, I'm not so sure....

              • 4. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
                peter minneapolis Level 4

                [Jongware] wrote:

                 

                (Short) Can't be done.

                 

                (Long) Well, it can, but not in a single replace. You'd have to first insert the text, then assign the correct character style.

                 

                (Slightly longer) You are physically re-inserting that final character, and so it will get that character style assigned. The usual way of finding-but-not-marking is to use a positive lookahead; but that doesn't work, because you would end up with two locations (the caret and the lookahead), and InDesign's particular implementation of GREP does not allow that. (Or rather -- irritatingly -- sometimes it seems to work if you press the Find button, but then a Change All is not going to work.)

                So that's why you have to insert at least one character in the Find What, and re-insert it in the Replace With fields.

                If all instances of the specific paragraph style need the prefixed text in a specific character style, consider redefining the paragraph style's autonumbering to include text and character style. Redefine the style, and all instances in the current document are changed. All future uses of the style automatically use the prefixed text and style. To update existing instances of the style in other documents with the new definition, use load paragraph styles; to apply the new definition to to other documents in an InDesign book, synchronize the styles. Search Google for terms like "InDesign paragraph styles numbered lists," "InDesign load styles," and "InDesign synchronize styles in book," without quotes for details.

                 

                HTH

                 

                Regards,

                 

                Peter

                _______________________

                Peter Gold

                KnowHow ProServices

                • 5. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
                  kmc27 Level 1

                  Thanks everyone for the explanation and ideas. I will give them a try and see what will work best for me.

                   

                  Peter Gold, I'm not sure how to modify the "bullets and numbering" portion of the Paragraph Style to add the "second item is free!" text. If I choose a list type of "bullets", InDesign will let me add the "second item is free!" wording in the "text after" field, but it also requires that I use a bullet character, which I do not need. Did I misinterpret what you wrote?

                  • 6. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
                    peter minneapolis Level 4

                    kmc27 wrote:

                     

                    Thanks everyone for the explanation and ideas. I will give them a try and see what will work best for me.

                     

                    Peter Gold, I'm not sure how to modify the "bullets and numbering" portion of the Paragraph Style to add the "second item is free!" text. If I choose a list type of "bullets", InDesign will let me add the "second item is free!" wording in the "text after" field, but it also requires that I use a bullet character, which I do not need. Did I misinterpret what you wrote?

                    Sorry if I wasn't clear. While Bullets and Numbering is the category, Numbering is what I intended to point you to. Autonumbers and bullets occupy a prefix area of paragraphs, but numbers differ from bullets in the ability to contain text only without numeric placeholders or bullet tokens. Usually there's a mix of text and numerics, such as "Chapter  ^H (the chapter number placeholder): ChapterTitleText." In this case, you'd delete all numeric placeholders from the Numbering Stye > Number text-entry field and type in "Second item is free!" You can see how it works with Preview turned on while you type, in the Paragraph Style Options dialog box.

                     

                    HTH

                     

                    Regards,

                     

                    Peter

                    _______________________

                    Peter Gold

                    KnowHow ProServices

                    • 7. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
                      [Jongware] Most Valuable Participant

                      P Spier wrote:

                       

                      [Jongware] wrote:

                       

                      (Short) Can't be done.

                       

                      (Long) Well, it can, but not in a single replace. You'd have to first insert the text, then assign the correct character style.


                      I usually think your solutions to stuff like this are better than mine, but in tis case, I'm not so sure....

                       

                      Yeah, sorry about that. I was focusing on explaining why it couldn't be done, when in fact it could be done very nicely -- except it doesn't involve Search & Replace. Other Peter's Bullets & Numbs idea is a very good one

                      • 8. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
                        Eugene Tyson Adobe Community Professional & MVP

                        It's Easier with a picture

                         

                        Text in Numbering.jpg

                        • 9. Re: Want to Insert Text at Beginning of a Paragraph Using GREP
                          kmc27 Level 1

                          Thanks for all the detailed answers. I tested using the numbered list, and it looks like it will be a big time saver in certain situations. In other cases I will need the inserted text to be editable just as regular text,  and in those cases I will end up doing some sort of two-step find and change.

                           

                          Thanks again for the ideas.