?
Solved

Get-ChildItem + Regex matching

Posted on 2014-10-24
2
Medium Priority
?
1,202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Starting up a Project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

752 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