Filtering out differently styled track numbers in filename

Hello Everyone,

A.] The objective is to set up a filter, which is applicable to file names. The filter should find the file names in which the track number matches the following numbering style:

101
206.
710.
911.

— Three numerals followed by a dot, all of which are located at the very beginning of the file name.

B.] Can one filter be made to cover in one application the matches for differently styled track numbers, all located at the beginning of the file name? Here follows an example of the track numbers in question:

10
74.
101.
706.
1-15.
6-15.

The method eludes me, completely, hence, I welcome your assistance — if only for the aforementioned, much needed A.]

%_filename% HAS ?

Thank you.

PS. The first number, as shown in each of the two series above, deliberately does not have the obligatory dot to avoid the message text getting re-formatted.

try:
%_filename% MATCHES "^\d\d\d\."

the \d stands for a digit - and 3 of them for 3 digits.
So, to filter for

Try:
%_filename% MATCHES "^\d-\d\d\."
or
%_filename% MATCHES "^\d+-\d+\."

and you can join them:
%_filename% MATCHES "^\d\d\d\." OR %_filename% MATCHES "^\d+-\d+\."

For those asking what the ^\d+- means:

image

A digit ("number") that exists at least once or unlimited times, followed by a - in the first occurence and followed by a . ("dot") for the second occurence.
The dot is a special character in regular expressions and has to be escaped with a \.

Thank you very much to you both, @ohrenkino and @LyricsLover. Especially also, to both of you for adding the explanations in there, too. I am beginning to recognise some of the patterns now.

1 Like

2 posts were split to a new topic: Insert text with a regular expression in the filename

A post was merged into an existing topic: Insert text with a regular expression in the filename

I would like to revisit this topic with a question (or two):

%_filename% MATCHES "^\d\d\d."`

the \d stands for a digit - and 3 of them for 3 digits.

  1. Since the "^\d\d\d." indicates 3 digits, what does the filter-syntax for "any number" of digits look like? Something like this, maybe?:

\d*\

  1. What is to gain by using the parenthesis around the Field name in filters, since it appears to be not a necessity? Perhaps prudence?

  2. Are the parenthesis around the filter-syntax required for an exact search of the term?

Thank you.

would be "any number, including no number at all".
If there should be at least 1 digit:
\d+

AFAIK there is no special purpose for parenthesis in the filter regular expressions.
I wonder where you found that.

would be "any number, including no number at all".
If there should be at least 1 digit:
\d+

Thank you very much, @ohrenkino

AFAIK there is no special purpose for parenthesis in the filter regular expressions.
I wonder where you found that.

My question concerning the parenthesis arose from utilising Boolean search parameters, which, I thought, perhaps might have some relevance here.

Could you please confirm whether parenthesis are to be used whenever an regular expression operator, such as one of the following, are deployed:

"$" or "^" or ""

For instance example, in the album field, I want to find anywhere in the description, the words:

(CD(followed by any number)^

After reading your reply, is this the correct way to construct the filter for it?:

%album% HAS (CD\d+\^

or,

should the caret be enclosed in parentheses, thus —

%album% HAS (CD\d+\"^"

The ^ and $ sign are also special characters in regular expressions.

The ^ means at position "Start of line"
The $ means at position "End of line"

"Line" in our case is the content of a tag or a filename for example.

Please have a look at the documentation:

No, the parenthesis are there to "collect/remember" the matched digits or characters.
For example, if you want to replace the matched characters with some other values, you need the parenthesis. They build groups for later use.

@ohrenkino gave you a solution for filenames, using such parenthesis:

If you want so search for parenthesis as ordinary character, you have to escape them like this \( for an opening bracket and \) for a closing bracket

If you really want to search for
opening bracket (
CD
opening bracket (
any number, including no number at all
closing bracket )

it would be something like
%album% MATCHES "\(CD\(\d*\)"

If you only search for
CD
followed by any number, including no number at all
it would be
%album% MATCHES CD\d*

In most cases you should also check, if there is a space before and after CD and brackets too.

Thank you, @LyricsLover

I have much to work with. My problem stems from using the caret "^", the regex special character, as part of the album name for multi-disc albums, for example:

Album name A (CD3^6)
Album name B (CD07^16)

Therefore, the caret is part of the field description, and part of the expression. How these play on each other, is what I am trying to understand.

Ahh, I see.

If you search for a text or number which has to be mandatory at the start position or at the end position, you have to use the ^ as very first character in your regular expression and/or $ as very last character in your regular expression.

if you search for ^ as part of your album name, as in your example
Album name A (CD3^6)
then you have to escape the ^ as special character with \^ like this:
%album% MATCHES \^
(this would search for any occurence of ^ in your current %album% tag).
Or more specifically:
%album% MATCHES CD\d+\^\d+
(search for CD followed by at least one digit, followed by ^, followed by at least one digit.)
And explicitly for your given content:
%album% MATCHES "\(CD\d+\^\d+\)"
(search for an opening bracket, followed by CD followed by at least one digit, followed by ^, followed by at least one digit, followed by a closing bracket.)

If you define that the above regular expression should only match, if this combination is the last part in your tag (= nothing is allowed to follow after the closing bracket), then you could add the $ function like this:
%album% MATCHES "\(CD\d+\^\d+\)$"

Here is a list of such special characters with "double meaning". They all need to be escaped to search for them literally.
(Sorry, I don't know the exact english word for this double functionality.)

Thank you for explaining it well, and for the examples you have provided along with it. I will learn how to apply them.

1 Like

(search for CD followed by at least one digit, followed by ^, followed by at least one digit.)
And explicitly for your given content:
%album% MATCHES "(CD\d+^\d+)"
(search for an opening bracket, followed by CD followed by at least one digit, followed by ^, followed by at least one digit, followed by a closing bracket.)

Having tried the aforesaid filter courtesy of @LyricLover, and not seeing the desired results, I tried out more of my own combinations for hours on end, to try and learn something from the experience. Of course, none did the job, because, eventually, I noticed an error I made in my original presentation here: I omitted a space between the word "CD" and the first digit following after it, which in turn is directly followed by the caret "^".

(
CD
Space
1st single, or, multi-digit
^
2nd single, or, multi-digit
)

Examples:

(CD_1^6)
(CD_10^12)

where: the underscore "_" represents the space.

I gave up here: %album% MATCHES \(CD\s\d+\^\d+\). Please, show me where I erred?

%album% MATCHES "\(CD\s\d+\^\d+\)"

Have a look at the notes about filter strings:

Parenthesis! Thank you, @ohrenkino. Always use parenthesis to enclosing the regular expressions?

(Also, do any "Literals" have to be put in parentheses whenever it is used in a regular expression?).

Not parenthesis (), double quotation marks ""

It feels like the person quickly downing an alphabet soup, expecting to speak the language fluently afterwards. :face_with_head_bandage:

Thank you, both.