# Iterate based on last result in set

**URL:** https://community.mp3tag.de/t/iterate-based-on-last-result-in-set/16569
**Category:** General Discussion
**Created:** [February 4, 2015, 6:34pm UTC](https://community.mp3tag.de/t/iterate-based-on-last-result-in-set/16569 "2015-02-04T18:34:51Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![mshockle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@mshockle](https://community.mp3tag.de/u/mshockle)
#### Post date: [February 4, 2015, 6:34pm UTC](https://community.mp3tag.de/t/iterate-based-on-last-result-in-set/16569/1 "2015-02-04T18:34:51Z")

</div>

Hello, I have been using mp3tag forever and I love it. Currently using 2.66 and was trying to deal with a specific issue I have been having. If you look at the attachment you will see a set of classical music songs by grieg. In this particular example I was fortunate enough to have all the track and disc number information so manually inputting them is not hard, but say I "needed" to do this?

Six Songs, Op.4 - The Orphan

simply put we regex: (.+?) - (.+) and replace $1 -$it. $2 where the value $it would be an iterated value from 1 to infinity. Each time we evaluate regex we would store the value of $1 and if it doesn't match the last value $it would be reset to 1 so we would have

Six Songs, Op.4 -1. The Orphan to Six Songs, Op.4 -6. Where Have They Gone? and Four Songs by Bj. Bjшrnson, Op.21 -1. The First Meeting etc.

Granted there are a number of hurdles that make this hard to pin down what we are looking for. For instance how do we know that the regex is ungreedy then split by - and then a greedy to end instead of : or some other character. So perhaps we let the user choose the regex at outset and show the last few regex's we used (you have this method on a number of scripts in the conversion tree 'tag-tag' 'tag-filename' where it will show the last few results. and if the regex results false on the first trigger then we should exit the script with a 'no results' thing.

The main feature request here then is how can we perform loops as we normally do but specify certain variables which we can access the next pass. I have till now created several script action groups to accomplish my formatting goals.

 ![](https://community.mp3tag.de/uploads/default/original/2X/f/f63874b0c98152ce9da3d5fab8937a07c804864f.png)

---

_[View the full topic](https://community.mp3tag.de/t/iterate-based-on-last-result-in-set/16569)._
