Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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}.

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2023-03-22 22:20 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.