5 Replies Latest reply: Jan 13, 2014 11:36 AM by Peter Spier RSS

    Excluding a character from "Change to" box that is in "Find what" box in GREP search


      Hello all! I am a first time poster but have been lurking around the forums for a few months. I'm trying to produce an InDesign document for a book I'm putting out, and there is a section where I have the following text:


      |  TAB  |1.|  TAB  |Lorem ipsum dolor etc.


      The text doesn't literally say tab, I jsut wanted to highlight that there is a tab of white-space on either side of the number for the line. This occurs numerous times in numerous chapters in the endnotes section. I want to remove the tabs so that the result is:


      1. Lorem ipsum dolor etc

      2. Lorem ipsum dolor etc

      3. etc etc


      I have identified that the way to find these sections is to use the GREP search function with \t\d+.\t. The + is there because the numbers go into the double digits in most chapters for the references. However, I do not want to remove the numbers, just the tabs. Is there any way to add an exclude feature to the "Change to" window of the search function? I've tried just leaving it as \d., but that literally changes the text to


      \d. Lorem ipsum dolor etc


      That's not good. I'm trying to avoid having to do all of this by hand, and of course by the time I get a resolution I'll probably have been better off doing it manually, but I'm looking toward the future and trying to ascertain the best way of streamlining such a process short of not having that kind of format in the first place when receiving the file from my employer


      Many thanks for your advice,



        • 1. Re: Excluding a character from "Change to" box that is in "Find what" box in GREP search
          Peter Spier ACP/MVPs

          First, let's establish that these are not part of an automatically formatted numbered list using the bullets and numbering options in the paragraph style (though they probably should be).


          If you don't want to make them part of a numbered list, you should be able to find (^\t)(\d+)(\t) and change to $2[space character of your choice]


          That said, I would make them the list and define it in a paragraph style, then find ^\s+\d+\s+ and replce with nothing, but change the change format to the correct paragraph style where the numbers and the spacer are defined. The advantage to this is that you can then rearrange, add or delete paragraphs in the list and the numbering will update automatically.

          • 2. Re: Excluding a character from "Change to" box that is in "Find what" box in GREP search
            1John5vs7 Community Member

            Thanks Peter! I appreciate your prompt feedback. I am very much a novice with InDesign, and so I'm not entirely sure how to do what you're saying as far as making the paragraphs part of a list. I know how to do that in HTML very well, and what I am doing is taking an existing InDesign document from a print publication my employer has produced and converting it to an e-book. As such, I am not adding or deleting any paragraphs. I'm simply marking this up so that I can export XML that will produce good .epub and .mobi files. I happen to know from experience that tabs translate as tabular data and I'll end up with a table or something like that and will then have to fix it in my HTML files. This is doable, but Adobe InDesign has a MUCH more powerful search function than my HTML editor, so I'd rather hammer it out in InDesign first.


            I will try your suggestion of (^\t)(\d)(\t) changed to $2[ ]. Thank you for the input. Very helpful answer!

            • 3. Re: Excluding a character from "Change to" box that is in "Find what" box in GREP search
              Peter Spier ACP/MVPs

              Just so you understand, [space character of your choice] is just my way of saying put something in this spot after the $2 (without the []) to use as a separator. It can be a regular space, a fixed width space, or a tab (but you'll want to set the tab in the paragraph style) so the text always starts at the same position. You could even set a left indent equal to the tab position, and a negative first line indent if you need the numbers to hang to the left of the paragraphs when there is more than one line.

              • 4. Re: Excluding a character from "Change to" box that is in "Find what" box in GREP search
                1John5vs7 Community Member



                   Just to affirm your assistance, this worked for me. I still don't understand the advanced search features perfectly, but I got the formatting fixed without having to sift through it manually. I found that replacing with "$2. " (minus the quotes) worked well. However, I noticed that searching for (\d). would turn up a digit followed by ANY kind of punctuation, not just a period. I assume therefore that . must mean something different in GREP than I'm thinking it does. I just wanted to find any digit before a full-stop. At any rate, that is something I can find a table of GREP search terms for. I didn't understand the $2 thing until I monkeyed with it. I'm typing now for future generations of newbies that might stumble upon my post. The $2 ignores the second character in your "Find what" field. So for example, if instead you had two tabs then a digit then a tab, you could search:


                Find what: (^\t)(\t)(\d)(\t)

                Change to: $3.


                This would take any occurrence of two tabs, a number, and a tab and replace with a period, ignoring and therefore not changing at all the number. The $3 is saying "ignore the third search term", in this case, the \d.


                A better approach would be to use +. This means "any time you see one or more occurrences of the searched-for character". This would look something like:


                Find what: (^\t+)(\d+)(\t+)

                Change to: $2.


                Here you are saying "Any time you see one or more tabs followed by one or more numbers and then followed by one or more tabs, ignore the digit, delete the tabs before and after, and add a full stop after the number. This is a very powerful search feature, once you understand what you're doing anyway. Hope that is helpful to someone at some point.

                • 5. Re: Excluding a character from "Change to" box that is in "Find what" box in GREP search
                  Peter Spier ACP/MVPs

                  Sorry, my fault entirely. I left out the period in the search query.


                  The correct query is (^\t+)(\d+\.)(\t+) if you are looking for "one or more" tabs on either side. The . in GREP is a wildcard for any character when used outside a class, so it would need to be "escaped" as \. .


                  If you don't know what the whitespace situation is, you can use (^\s+)([\d.]+)(\s+) which will find all whitespaces, not just tabs. The [\d.] class is any digit and the period (inside the class it's literal), and it would find any combination of digits and periods, like 1.2.33  in case your numbering runs that way.