LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-19-2011, 11:00 PM   #1
xavitxus
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
Help with regular expression


Can someone please explain this regular expression:

'.*/\..*'

It's making me crazy
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 08-20-2011, 12:11 AM   #2
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 390

Rep: Reputation: 150Reputation: 150
Quote:
Originally Posted by xavitxus View Post
Can someone please explain this regular expression:

'.*/\..*'

It's making me crazy
Alrighty. I'll split the regex in two parts to explain it:

.*/
A dot represents one character, any character. The asterisk is a multiplier that means the previous expression can occur zero or more times, and the slash is just a literal forward slash. So this part of the regex can be read as: "Match any amount of characters followed by a forward slash".

\..*
Since the dot has a special meaning in the regular expression, it's necessary to escape the first dot to instruct the program that we're looking for a literal dot, not the regex dot metacharacter. To use a metacharacter as a literal character write a backslash before it. The following .* is the same as the first part. This can be read as: "Match a dot, followed by any amount of characters".

So the full regex can be read as: "Match any amount of characters followed by a forward slash, followed by a dot, followed by any amount of characters".

Quote:
Originally Posted by osvaldomarques View Post
Code:
find . \( ! -regex '.*/\..*' \) -type f -name "whatever"
The regular expression will match hidden files and directories of the form dir/.file. But since it's negated in the find option (! -regex '.*/\..*'), it will have the reverse effect, matching everything except hidden files and directories.

Hope that helps.

Last edited by Diantre; 08-20-2011 at 12:15 AM.
 
2 members found this post helpful.
Old 08-20-2011, 09:40 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,150
Blog Entries: 3

Rep: Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407
Moved: Posts created to new thread and is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 08-28-2011, 04:44 PM   #4
xavitxus
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks a lot Diantre, in my country we say "Meridianamente Claro", it means "it's very clear", thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with regular expression Feyd-Rautha Programming 8 04-21-2008 11:18 AM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 08:13 AM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 10:08 AM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM
regular expression gumby Programming 3 07-15-2003 12:13 PM


All times are GMT -5. The time now is 11:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration