RegEx question

Hello everyone,

I have two file formats below that I need to copy to their respective folders 8323434 and 869343434.1.

What is the RegEx expression for just the number portion (ie. 8323434 and 869343434.1)?

file 1: SOMEWORD 8323434.pdf
file 2: SOMEWORD 869343434.1.pdf

Also, if you could point me to to a good resource on building RegEx, that would be greatly appreciated. Thank you in advance.

You should try to ask your favorite internet search engine. Regular expression are not secret science. There are tons of information to find in internet …

$folder = Get-ChildItem .\path\to\folder -Filter *.pdf |
Select-Object fullname,basename

# Get number from filename then create folder
# New folders are created in files' original location
foreach ($f in $folder){
$f.basename -match '\d+.*' | Out-Null
$newfolder = Join-Path -Path ($f.FullName | Split-Path) -ChildPath $Matches[0]
If (-NOT(Test-Path $newfolder)) {New-Item $newfolder -ItemType Directory | Out-Null}
Move-Item -Path $f.FullName -Destination $newfolder

Here’s an interactive regex tool:

Thank you everyone. Greatly appreciated.

The above script works great. Just a small thing. How do I have it so the files SOMEWORD 8323434.pdf go to a folder 8323434.1 instead of 8323434?

All files SOMEWORD 8323434.pdf >> folder 8323434.1

All files SOMEWORD 869343434.1.pdf >> folder 869343434.1

All files SOMEWORD 565643434.2.pdf >> folder 565643434.2

so on…

Many thanks…