Solved

Get-ChildItem + Regex matching

Posted on 2014-10-24
2
855 Views
Last Modified: 2014-10-24
I've got a folder containing many temp files, and i'm trying list files that have names between 1 and 4 hexadecimal characters, with ".tmp" as the extension.

When i run the following, i can match filenames of exactly 4 characters:

Get-ChildItem -Path C:\temp\files | where-object {$_.Name -match '^[a-f0-9]{4}?.tmp$'}

And this gives me all that are 3 characters:

Get-ChildItem -Path C:\temp\files | where-object {$_.Name -match '^[a-f0-9]{3}?.tmp$'}

According to http://ss64.com/ps/syntax-regex.html, I should be able to replace the number inside the curly braces with a range of the number of matches (ex. {1-4}) but that returns 0 results. What am I missing?
0
Comment
Question by:Chris Valentino
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40402360
Read your link again: the range is specified with a comma, not a minus:
Get-ChildItem -Path C:\temp\files | where-object {$_.Name -match '^[a-f0-9]{1,4}?.tmp$'}

Open in new window

0
 

Author Comment

by:Chris Valentino
ID: 40402372
Good catch, thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now