Free tech support / small logo


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.









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
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 something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

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











Remember personal info?


Please note that I will never send you any unsolicited 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.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!

Linux Journal: Free Issue!


© 2002 - 2012 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]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.