Solved

Get-ChildItem + Regex matching

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

896 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