Search only files with numerical names (Regex Pls)

General discussion related to "Everything".
Post Reply
asimetron
Posts: 5
Joined: Thu Mar 09, 2017 4:00 pm

Search only files with numerical names (Regex Pls)

Post by asimetron »

Hi good day.
I would like to know if someone can help me create a regular expression that allows me to search only files that contain numbers in their name but not words and letters.

Search these:

Code: Select all

10000978 677226145670340 3267159752656730961
10255250 676471382412483 8114984222048456769
05022012921
Exclude these:

Code: Select all

5022 594720673920888 369554635 N
Metal painted0114 4 thumblarge
(1) IMG-20170321-WA0001
That is, do not also look for files that have numbers and letters, but exclude all those that contain letters or words and only throw me in the search, those files whose name explicitly contains only numbers, no matter if they have spaces or any other character.

I've been trying all day and the closest I get is this, but some files with letters also appear.

Code: Select all

^[0-9]
Thank you so much
void
Developer
Posts: 16735
Joined: Fri Oct 16, 2009 11:31 pm

Re: Search only files with numerical names (Regex Pls)

Post by void »

With regex disabled from the Search menu, please try searching for:
regex:"^([0-9]|[[:punct:]]|[[:space:]])*$"

regex: = enable regex search modifier
" " = escape spaces and |
^ = match start of filename
( ) = group
[0-9] = match literal characters 0 to 9
| = OR
[[:punct:]] match a punctuation character
[[:space:]] match a space character
* = match previous group any number of times
$ = match end of filename.

Please try the following search if you only need all numbers or spaces:
regex:"^[0-9 ]*$"
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Search only files with numerical names (Regex Pls)

Post by NotNull »

... and if those filenames also have extensions - like "0123.doc", "123 456.html" or "345;446.jpg" - try it with:

Code: Select all

regex:"^[0-9[:punct:][:space:]]*\.[^\.]*$"  ext:doc;html;jpg

EDIT:explanation
regex: Do a regular expression search
^ Starting from the first character of the filename
[0-9[:punct:][:space:]]* check for multiple numbers, spaces or punctuation characters
\. followed by a dot (".")
[^\.]* followed by characters that are NOT a dot
$ until the end of the filename

ext:doc;html;jpg And the [^\.]* part matches doc or html or jpg


@void: Why the [:space:]? Are there other "space characters" other than the regular space allowed in filenames? (just curious)
therube
Posts: 4977
Joined: Thu Sep 03, 2009 6:48 pm

Re: Search only files with numerical names (Regex Pls)

Post by therube »

Does this do it?

Code: Select all

regex:^(\d+\s*\d*){1,}$
With that the \s may end up taking more then wanted (rather then just "space", so maybe better with :space: instead.


Ah, what Void posted, regex:"^[0-9 ]*$", is much more efficient then what I posted (but looks to return the same results).
asimetron
Posts: 5
Joined: Thu Mar 09, 2017 4:00 pm

Re: Search only files with numerical names (Regex Pls)

Post by asimetron »

Wow, that was fast.

I am very grateful "with both" for their time and their kind response.
Also by breaking down the syntax of the strings contained in the raised expressions.
Although I am not a programmer, I really like this language of regular expressions and, I am trying to learn it just like a turtle walks.

Many thanks.
You made my day.

God bless you with much love, life, health, peace, tranquility and abundance.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Search only files with numerical names (Regex Pls)

Post by NotNull »

Thank you for your kind words, asimetron!
asimetron wrote: Tue Sep 17, 2019 4:57 pm Although I am not a programmer, I really like this language of regular expressions and, I am trying to learn it just like a turtle walks.

I am not a programmer either. Most of what I know about regular expressions, is thanks to Everything and the good people on this forum. Regex can be very complicated, but the Everything regex help (*) shows a smart subset that makes it a lot less overwhelming. If you use only those, can do at least 70% of your regex tasks (my estimation). That's how I learned the basics.

Here you can find a couple of very useful regex links.

And you can always ask on this forum, of course :)


(*) Menu:Help > Regex Syntax or https://www.voidtools.com/support/every ... ing/#regex
void
Developer
Posts: 16735
Joined: Fri Oct 16, 2009 11:31 pm

Re: Search only files with numerical names (Regex Pls)

Post by void »

@void: Why the [:space:]? Are there other "space characters" other than the regular space allowed in filenames? (just curious)
PCRE will match the following with [[:space:]] or \s
  • HT (9) 0x09
  • LF (10) 0x0A
  • VT (11) 0x0B
  • FF (12) 0x0C
  • CR (13) 0x0D
  • Space (32) 0x20
Filenames can contain the following:
  • Space (32) 0x20
Filenames can not contain the following:
  • HT (9) 0x09
  • LF (10) 0x0A
  • VT (11) 0x0B
  • FF (12) 0x0C
  • CR (13) 0x0D
Renaming a file with one of the above characters will result in the error 123: ERROR_INVALID_NAME: The filename, directory name, or volume label syntax is incorrect.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Search only files with numerical names (Regex Pls)

Post by NotNull »

Thank you!

Don't remember if I mentioned this before, but I really like the way you present information. Correct, complete, to the point, structured, no room for misunderstanding misinterpretation.
Post Reply