An unofficial blog that watches Google's attempts to move your operating system online since 2005. Not affiliated with Google.

Send your tips to gostips@gmail.com.

March 25, 2009

Find and Replace in Google Docs

Google Docs finally replaced the partially functional "find & replace" dialog inherited from Writely with an inline bar that actually works. Just select "Find & replace" from the "Edit" menu or type Ctrl+F to make the bar visible. To find the next match, click on "Find next" or type Ctrl+G.

The option can be used to find a text in your document and to replace it with a different text. If you click on the small arrow next to the first input box, you'll be able to set some restrictions: case matching, finding only whole words or using JavaScript-style regular expressions. For example, to remove all the email addresses from a document, use the following regular expression for email addresses:

[a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}

If you know some other potentially useful regular expressions in a word processor, share them in the comments.


{ via Google Docs Blog }

18 comments:

  1. jane@doe.museum wouldn't be removed. That regexp is incorrect. Change [a-zA-Z]{2,4} to [a-zA-Z]+

    ReplyDelete
  2. That final {2,4} should be {2,6} if you want that expression to work for more email addresses like .museum . Really, if you want it to work for future TLDs that may not even exist yet, you should go with {2,} .

    ReplyDelete
  3. Thanks, I updated the expression.

    ReplyDelete
  4. There are still plenty of problems with your regular expression

    Try it with the very common
    name+filter@gmail.com

    Email addresses can use any characters before the @ sign, not just alphanumerics. (See RFC 2822 for details)

    ReplyDelete
  5. this well known regexp implements RFC 2822
    http://code.iamcal.com/php/rfc822/full_regexp.txt
    but i always use this one
    (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

    ReplyDelete
  6. and the second one will find text only outside html tags
    ~(?!<.*)(?<!\w)(words|to|find)(?!\w|[^<>]*>)~i

    ReplyDelete
  7. Does somebody know how to find in Google docs all carriage return and replace them with nothing. Would be very useful. That's one of the few case I have to launch Winword (^p)again.

    ReplyDelete
  8. @Guy DERIDET: You could try viewing the HTML source and removing the
    tags.

    ReplyDelete
  9. Please don't regexp match email addresses, it just can't be done in a sane way!

    It's strange that there isn't a command for testing email addresses in PHP/ASP.net. You need to send the email to be sure if it works or not, if there is a command to do a partial send then that could be used. E.g. Just connect to the mail server and say that you have "Rcpt to:<emai>" and check if it is accepted.

    ReplyDelete
  10. I'm used to hitting the return key multiple times for successive searches, but this will delete the string that's found in Google Docs... argh.

    ReplyDelete
  11. > I'm used to hitting the return key multiple times for successive searches, but this will delete the string that's found in Google Docs... argh.

    SECOND THIS! Very annoying. Another annoyance is that if I want to search across a few tabs, I have to enter my search string again. Using my browser's find, I could enter it once, then just *switch tab* *ctrl-g*, which is much more efficient.

    I think this is great for those who use regex's, but for the rest of us it's just annoying. I think there should be an option that we can set so the new find bar can only be brought up through the menus.

    ReplyDelete
  12. Philipp, I found out something wonderful today that I just had to share. Instead of using ctrl-f, hit 'f' twice to get to your browser's search :)

    The new find key is ctrl-f-f ;)

    ReplyDelete
  13. > Philipp, I found out something wonderful today that I just had to share. Instead of using ctrl-f, hit 'f' twice to get to your browser's search :)

    I'm very jealous..this doesn't work on mac os x.

    ReplyDelete
  14. Any way to disable this custom find bar????? VERY ANNOYING!

    ReplyDelete
  15. You can disable it by installing firebug, or using developer tools on chrome.

    Open the javascript console, and type "WritelyVars.enable_find_bar=false".

    You'll need to do this every time.

    You should try zoho, it generally works better, and no stupid find bar.

    ReplyDelete
  16. y would you guys put a character limit on this function...totally useless now ;( back to ms word...

    ReplyDelete
  17. I wish there was the ability to "find and replace" by "color"

    we use Google docs with coloring sections and it would be very helpful to be able to find and replace by color as an option in conjunction with the traditional text options such as whole or entire word etc.

    ReplyDelete
  18. What about wildcards? Is there any way to find and replace using wildcards?

    ReplyDelete