Regex: Return Videos That Do Not Contain Year of Release

General discussion related to "Everything".
Post Reply
NeonLadder
Posts: 3
Joined: Fri Mar 23, 2018 9:00 pm

Regex: Return Videos That Do Not Contain Year of Release

Post by NeonLadder »

I am trying to locate all video files which do not contain a year surrounded by parentheses. For example, of the following 2 files I only want to see 'MyMovie1967.mkv' in the results. I will then add the parentheses myself.

MyMovie1967.mkv
MyMovie (1967).avi

I thought that this search might do what I need, but this also returns files with the year in parentheses.

(^.+)((\([012345679]{4}\)){0})

Image

Any help would be greatly appreciated.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NotNull »

Does this work or you?:

Code: Select all

regex:^.*[^\(][12][0-9]{3}[^\(].*
It wil report all files containing 4 numbers (starting with 1 or 2, because 1967 or 2018) without surrounding ()
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NotNull »

I should have tested that before posting. Here is a slightly better version:

Code: Select all

regex:^.*[^(0-9)\(][12][0-9]{3}[^(0-9)\)].*
This will exclude larger numbers, too.
NeonLadder
Posts: 3
Joined: Fri Mar 23, 2018 9:00 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NeonLadder »

That expression returns what I believe is the list of files I need!

I did notice however that it also returns the following file:

Image

I am curious as to why this file is included when for example the following file is not included:

Image

Is this what your expression equates to?

Get filenames that:
(1) begins with any character one or more times
(2) NOT followed by a digit OR an opening parenthesis
(3) followed by 1 OR 2
(4) followed by three digits
(5) NOT followed by a digit OR a closing parenthesis
(6) followed by any character one or more times.
therube
Posts: 4985
Joined: Thu Sep 03, 2009 6:48 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by therube »

Files that don't have 4 digits enclosed in parens.

Code: Select all

!regex:\(\d\d\d\d\)
That way it can include your movies from the 1700's too ;-).
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NotNull »

NeonLadder wrote:That expression returns what I believe is the list of files I need!

I am curious as to why this file is included
Because it's name also includes a 4 digit number that *isn't* enclosed by (): 2049

The match is for 4 digits that aren't surrounded by other digits or ()
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NotNull »

therube wrote:Files that don't have 4 digits enclosed in parens.

Code: Select all

!regex:\(\d\d\d\d\)
That way it can include your movies from the 1700's too ;-).
That would also match "Hello World.txt", I think.

Hahaha, movies from the 1700's :D Starring the great-great-grandparents of the Lumiere brothers :-)
Stamimail
Posts: 1122
Joined: Sat Aug 31, 2013 9:05 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by Stamimail »

NotNull wrote:

Code: Select all

regex:^.*[^(0-9)\(][12][0-9]{3}[^(0-9)\)].*
NotNull, try this, literals will work:

Code: Select all

regex:[()]
I'm just learning now some Regex, and I didn't understand why you tried to escape by "\"
Do you know Regex flavor needs "\" ?
NeonLadder
Posts: 3
Joined: Fri Mar 23, 2018 9:00 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NeonLadder »

Thanks NotNull and therube. I have exactly what I need, and it is greatly speeding up the process of cleaning up my library!
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NotNull »

Stamimail wrote:
NotNull wrote:

Code: Select all

regex:^.*[^(0-9)\(][12][0-9]{3}[^(0-9)\)].*
NotNull, try this, literals will work:

Code: Select all

regex:[()]
I'm just learning now some Regex, and I didn't understand why you tried to escape by "\"
Do you know Regex flavor needs "\" ?
Hey, that works too! I had no idea .. Nice catch!
I was escaping the (), because parentheses are also used for grouping - like gr(a|e)y in the Everything documentation - but that seems unneeded.Don't know if other Regex flavors need the escaping.

BTW: Everything uses the Perl regular expression language.
ovg
Posts: 294
Joined: Thu Oct 27, 2016 7:19 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by ovg »

inside character class [] only some characters need to be escaped:
www.regular-expressions.info
"In most regex flavors, the only special characters or metacharacters inside a character class are the closing bracket ], the backslash \, the caret ^, and the hyphen -. The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash. To search for a star or plus, use [+*]. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.
In most regex flavors, the only special characters or metacharacters inside a character class are the closing bracket ], the backslash \, the caret ^, and the hyphen -. The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash. To search for a star or plus, use [+*]. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.

To include a backslash as a character without any special meaning inside a character class, you have to escape it with another backslash. [\\x] matches a backslash or an x. The closing bracket ], the caret ^ and the hyphen - can be included by escaping them with a backslash, or by placing them in a position where they do not take on their special meaning. The POSIX and GNU flavors are an exception. They treat backslashes in character classes as literal characters. So with these flavors, you can't escape anything in character classes.
From http://www.regular-expressions.info/charclass.html
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Regex: Return Videos That Do Not Contain Year of Release

Post by NotNull »

Useful info. Thanks, ovg!
Post Reply