is now part of CreativePro.com!

Remove the Numbers at the Beginning of a List with a Simple GREP

14

I often need to format material that someone has sent in a text file, or from text copied from a web page. One of the most annoying things is dealing with a long list of numbered paragraphs, because I need to strip off the manual numbers and replace them with automatic paragraph numbers.

For example, I just grabbed this text from Thad McIlroy’s wonderful Future of Publishing site, pasted it into an InDesign text frame and applied automatic numbering to it. The result (with Type > Show Hidden Characters turned on) is this:

RemoveSpaces2

To clean it up, I need to remove that second set of numbers — the “hard coded” ones that are actually typed in the text — and the extra spaces that follow. Fortunately, it’s very easy with a quick GREP find/change:

You can open Find/Change, select the GREP tab, and type this into the Find what field: ^\d+?\.\s+

Then, leave the Change to field blank (so that it actually deletes whatever it finds).

RemoveSpacesFromNumberedList

If you want to assign a paragraph style to each paragraph it finds, then use the Change Format field at the bottom of the dialog box. (You may need to click More Options to see that.) However, if you assign formatting here, then InDesign will not delete the text it finds! It’s kind of tricky… if there is formatting specified and the Change To field is blank, then it applies that styling and leaves the text. If both Change To and Change Format are blank then it deletes the text. So to assign a paragraph style: first run the find/change to apply the style, and then run it again with the Change Format blank, so that it removes the hard-coded numbers and spaces.

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Eugene Tyson says:

    I do this quite a lot too – except a bit simpler on the GREP :)

    ^.+?\s+

    I only do this on Selected Text though. I wouldn’t run this through a whole document.

    I do it this way because sometimes some people tend to add a Space before the number, or sometimes even a tab, or sometimes they will put a space between the number and the full stop, like so “10 .”

  • Eugene Tyson says:

    Actually (on testing) it won’t find something like (10 .) at all.

    Hmm, I’m sure there has to be a “catch all” GREP?

  • When dealing with bulleted character instead of number, I use this:
    ^\s?~8\s+

    When dealing with long sequence of numbers like from 1.0 to 1.0.0.1 you I use this:

    ^\d\.\d(\.\d)?(\.\d)?\s+

  • Pierre Labbe says:

    Hi,
    Loïc Aigon had made a script on this subject. The description (in French) is here: https://www.loicaigon.com/blog/?p=59
    The script “false_list_to_true_list.jsx” can be downloaded here: https://www.loicaigon.com//downloads/false_list_to_true_list.jsx
    And should work on the English text as it uses the same regex that indicated in this post.

  • Masoud says:

    Hi

    For testing, I copy a bunch of numbered paragraphs from MS Word and paste into InDeisgn, but David,s command (^\d+?\.\s+) doesn’t work for me!?! but Eugene Tyson (^.+?\s+) works well. I don,t know why the first command (David,s command) doesn,t answer to me and InDesign warns me: “can,t find match”.
    but very handy.
    Now could you help me to find a complete list of these kind of useful commands for GREP?

    Thanks a lot

  • @Masoud: my grep works for me for numbered lists copied form Word. But note that my grep code searches for:
    a number, followed by a dot (period), followed by one or more spaces
    If your numbered list has no dots, for example, then you’d need to remove the backslash-dot part of the code.

    As for additional codes, I suggest doing a search on our site for grep, such as these pages:
    https://creativepro.com/grep
    and
    https://creativepro.com/favorite-grep-expressions-you-can-use.php

  • Thad McIlroy says:

    I’ve been wanting to get rid of the hard-coded numbering because I constantly revise the list. I build the site directly in WordPress these days, and the built-in number is very ugly. So I keep doing it the hard way.

    Best regards, Thad

  • @Thad: LOL. No reason to apologize for it. It’s not WP or you, it’s the whole copy and paste thing from one app to another, especially a web browser to InDesign. That’s where even html’s OL formatting gets turned “hard-coded.”

  • Stewart says:

    I often get these lists with and without periods after the numbers. Might I suggest
    ^\d+?\.?\s+

  • Jongware says:

    @Stewart: absolutely!

    Just to nit-pick: your first ‘?’ is not necessary here. It selects ‘the shortest possible sequence of digits, but of course that’s equal to the longest possible in this context.

  • incblotter says:

    I’m trying to do the opposite: turn a numbered list into a “hard-coded” list. FYI, I need hard-coded numbers for a endnotes-to-links script to work (part of my epub conversion workflow). Any suggestions?

  • Nirav Mehta says:

    Thanks a lot for this!! Tried this with TextWrangler and the regular expression worked perfect.

    This would save me hours of work!!

  • Shlomit Heymann says:

    Thanks! Exactly what I was looking for :)

  • >