Solved

Get-ChildItem + Regex matching

Posted on 2014-10-24
2
949 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

770 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