Solved

Get-ChildItem + Regex matching

Posted on 2014-10-24
2
1,032 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 84

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …

733 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