Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regex pattern to find directories only with digits

by graff (Chancellor)
on Apr 12, 2013 at 03:03 UTC ( #1028263=note: print w/ replies, xml ) Need Help??


in reply to Regex pattern to find directories only with digits

If I were trying to get just the entries in my current working directory whose names consist entirely of digits, I'd do it like this:

my @digit_dirs = grep /^\d+$/, <*>; print join( "\n", @digit_dirs, "" );
If the entries of interest were in fact all "yyyymmdd" digit strings, I'd replace the "+" in the grep regex with {8}.


Comment on Re: Regex pattern to find directories only with digits
Select or Download Code
Re^2: Regex pattern to find directories only with digits
by Bindo (Acolyte) on Jun 20, 2013 at 10:19 UTC

    Thank you very much good people. I totally understood the concept. You all are the best. By the way if I get a satisfactory answer to a thread that I have started is there a way of closing/locking it? Cos I receive lot of reminders from root saying that I'd have to reply ...etc. Im just a beginner gentlemen so please let me know if there are any rules that I should follow. thanks

      If you are on unix or similar shell, use:
      ls|grep -P "^.*\d{8}.*"
      -P in grep is for using perl regex within shell grep.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2015-07-02 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls