Welcome Guest

Pages: 1
Set year from regex of folder name
ZimzimPostJune 16, 2016, 11:08
Newbie
Posts: 9
Registered:
November 11, 2015, 04:40
Normal topicSet year from regex of folder name

I'm not sure why I'm struggling with this as it seems a simple enough idea.

My folder names always include the year:

Blah_blah_blah_2015_Audio
Blah_blah_blahsomething_2016_Audio

I want to read this year from the folder name, and set it to the year field of the contained MP3s

I have set variable 3 to the folder name using Get Property

I am trying to use "Find all matches for regular expression" to set the result to the Year field (see pic).

Doesn't appear to work this way, I must be thinking about this completely wrong!

I'm using a fairly simple regex that should match a block of 4 digits that starts with a 2 (you know, so I don't have to update it again for a thousand years) and to minimise the possibility that the title may contain some other 4 digit block.
Image

ZimzimPostJune 16, 2016, 11:57
Newbie
Posts: 9
Registered:
November 11, 2015, 04:40
Normal topicRe: Set year from regex of folder name

Aha! Solved it setting the result to the descriptions and seeing what was going on. I had this completely back to front. I've now done it with two "Find all matches for regular expression", removing everything before the year with one and replacing the variable, then running it again for everything after the year, leaving just the year in the variable which can then be set as the result to the year field. Maybe there's a quicker way, but at least this works.

2MR2PostJune 16, 2016, 12:23
Avatar photo
Administrator
Posts: 2085
Registered:
August 23, 2012, 19:27
Normal topicRe: Set year from regex of folder name

You got it. The statement is a replace not an extraction.

You could do the following:

Set Variable 0 to "\~"
Find first match for regular expression "(2[0-9]{3})" in field Variable 3, replace with "\v0$0\v0" in field Year
Find "\~" in the Year field, remove it and everything before
Find "\~" in the Year field, remove it and everything after

If there is no sequence found, the above will result in a strange Year field.

The following is safer but should be executed grouped.

Set Variable 0 to "\~"
Find first match for regular expression "(2[0-9]{3})" in field Variable 3, replace with "\v0$0\v0" in field Variable 1
Find "\~" in Variable 1, remove it and everything before, set state
if true
Find "\~" in Variable 1, remove it and everything after
Set the Year field to "\v1"
endif

Whatever works for you 🙂

ZimzimPostJune 16, 2016, 13:51
Newbie
Posts: 9
Registered:
November 11, 2015, 04:40
Normal topicRe: Set year from regex of folder name

Thanks for this, really appreciate your going the extra mile to explain ways to improve things 🙂

2MR2PostJune 19, 2016, 21:49
Avatar photo
Administrator
Posts: 2085
Registered:
August 23, 2012, 19:27
Normal topicRe: Set year from regex of folder name

I've decided to expand the functionality of the regex statement. v3.12.1 will support the current replace function and adds match extraction and match location extraction. So once, v3.12.1 is released, you can do it with a singe regex statement. 🙂

ZimzimPostJune 19, 2016, 22:13
Newbie
Posts: 9
Registered:
November 11, 2015, 04:40
Normal topicRe: Set year from regex of folder name

Awesome! Many thanks/

Pages: 1
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.019 seconds.