Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

Question about regular expressions

A reader of Learning Unix for Mac OS X Panther writes in to ask for an explanation of the regular expression shown in this command:
du -s * .[^.]*

Dave's Answer: This regular expression is easily understood if you remember that to exclude a character from an expression you need to negate it with the ^, but to do that, you need to set off what you're negating from the rest of the expression - the [ ] part.

So now you should be able to see that the expression matches all files or directories that begin with a dot but don't have a dot as their second character, followed by zero or more characters.

In essence, this regular expression matches any dot files other than '..'.

If this seems overwhelming and you're still quite interested in learning more about regular expressions, there's a very good book from O'Reilly about regular expressions called Mastering Regular Expressions. It's not poolside reading, but it'll get you to the next level.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

can you please email me the regular expression that can limit the occurances of the same number for eg.

if you are limiting the maximum occurance to 3 then no number can repeat more than thrice in the string

eg. 1122338765 should be valid

but 1122224564 should not not be valid

Posted by: sreeju at June 12, 2005 7:27 AM

but should't
du .[^.]*
mean
'.'
followed by
anything not a '.'
followed by 0 or more of
anything not a '.'
yet it hits for .a.b.c
why does [^.]* mean "not a dot" followed by "0 or more of any char", rather than
"not a dot" followed by "0 or more or the preceding (which was "not a dot")"

Posted by: egkamp at June 21, 2005 8:52 PM

bash does NOT use regular expressions. Bash uses FILE GLOBS (see section "Pattern Matching" in bash).

Posted by: monsieur at May 17, 2006 5:33 AM

IT SAYS THAT INTERNET BROWSER DO NOT START ON SETTINGS SO HOW DO I CHANGE IT

Posted by: DAZ at February 17, 2007 5:37 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Uniblue: Free Virus Scan

Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]