4 Replies Latest reply on Dec 5, 2012 3:37 AM by mitzi187

    Remove numbers using GREP?


      Hi Guys,


      Could anyone please help me? I have only just discovered GREP within inDesign so Im not that clued up on it. I have searched the web, but can't seem to find a way of removing sequntial numbers from a document - is this possible?

      I essentially have several documents which contain old page numbers in parentheses- Is it possible to use GREP to find and delete them, including the brackets? i.e, [1],[2],[3],etc.



        • 1. Re: Remove numbers using GREP?
          Marijan Tompa [tomaxxi] Level 4



          Sure, try this: \[\d+\]


          This will find any number of numbers between square brackets including brackets.


          Hope that helps.



          Marijan (tomaxxi)


          • 2. Re: Remove numbers using GREP?
            mitzi187 Level 1

            Wow! thanks for the quick response. That totally worked, thank you so much, you have saved me hours of work!

            • 3. Re: Remove numbers using GREP?
              [Jongware] Most Valuable Participant

              GREP is unable to find 'sequential' numbers, but if you want to remove "all numbers between square brackets", that can be done with this:




              (and replace with nothing)


              A little break-down: the characters [ and ] are special in a GREP expression -- they indicate a custom group of characters. For example, the sequence [0-9] will search for a single digit, from "0" to "9", and the sequence [a-fh-zABC] will search for a single character from the set "a to f, h to z, or A or B or C". Because of this special behavior, if you want to search for a literal [ or ], you have to add a backslash, which instructs GREP to 'escape' the default meaning. That's why my query says "\[" and "\]".


              The sequence [0-9] will search for any single digit, but as it is such a popular range, it has a code of its own: \d ('d' for 'digit'). Similar shortcuts for character ranges are \u ("uppercase") and \l ("lowercase"), \w ("word character", i.e., any alphabetic or numeric character), and \s (any white space character). The inverse is also possible: \D will match every and any character except a single digit.


              The + indicates that the previous code (which is the single character group code for digits) may be repeated; it stands for 1 or more. Two similar codes are * -- 0 or more, i.e., "only if it's there" -- and ? -- zero or 1 time.


              With a few GREP codes, combinable in literally endless different ways, you can efficiently search for a variety of text. It seems just about everything is possible, one way or another ... well, expect for searching for sequential numbers, as GREP cannot count!

              If you want to know more about it, Peter Kahrel's O'Reilly Shortcut "GREP In InDesign" is considered the best guide. Don't be put off by the "CS3/CS4" in the title; this has hardly changed, and Peter even updated the latest version to include CS5-specifics as well.

              1 person found this helpful
              • 4. Re: Remove numbers using GREP?
                mitzi187 Level 1

                Thanks for the breakdown -extremely useful. Much appreciated