# How to loop regular expression?

**URL:** <https://community.mp3tag.de/t/how-to-loop-regular-expression/19184>\
**Category:** Support\
**Created:** [July 31, 2017, 3:14pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184 "2017-07-31T15:14:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [July 31, 2017, 3:14pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/1 "2017-07-31T15:14:10Z")

</div>

I need help with a simple task

Here are some of the possible values than need changing:

```
#9x
#9X
#9XX
#9xxxxxxx
#9XXXXXXXXXXXxetc.

```

And here is how they all should look like when the action is executed upon them

```
#9X

```

All I have know is this code for format value

```
$regexp(%GENRE%,'9XX','9X')With this code the change is done, but only once; and only on capital letters . So it would have to be executed every time unknown amount of times in order to really do the job and with a second version for lower letters and third version taking into account >Xx< and >xX< possibilities

```

So how do I merge those tasks into one line and loop them until there are no lower and upper case x's left, that are adjacent specifically to \>\>#9\<\<

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [July 31, 2017, 4:26pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/2 "2017-07-31T16:26:37Z")

</div>

$regexp(%GENRE%,'^(?i)#\*9x\*','#9X')

Your format regexp shows a different string than the first example.

Just remove the #\* and # from the above depending.

^ match start of string  
(?i) turn on case insensitivity

# matches

- matches above any number of times. 0 to infinity  
9 a literal, number 9. Change this to \d if you want to match any digit  
x another literal like above
- matches x any number of times like # above

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [July 31, 2017, 4:26pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/3 "2017-07-31T16:26:43Z")

</div>

> [@Zerow](#):
>
> ... I need help with a simple task ... And here is how they all should look like when the action is executed upon them #9X ...

Example for single value in tag-field:

**$regexp('#9xXXXXXXx','^(#\d+)(\D).\*$','$1\u$2')**

Result: #9X

... or ...

Example for floating value within tag-field:

**$regexp(' test \r \n #9xXXXXXXx \r\n test','(?:.\*)(#\d+)(\D)(?:.\*)','$1\u$2')**

Result: #9X

DD.20170731.2026.CEST, DD.20170801.0754.CEST

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [July 31, 2017, 5:44pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/4 "2017-07-31T17:44:54Z")

</div>

> [@stevehero](#):
>
> [...]  
> ^ match start of string  
> [...]

String, and not the whole tag field?

I am making sure because [as always] I did not precise enough: there can be many other values in that tag field; and they all must be left alone exactly as they are. I only need to treat x's [and later on other variations of numbers and letters, to which I will modify the descibed / received code]

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [July 31, 2017, 6:54pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/5 "2017-07-31T18:54:34Z")

</div>

> [@Zerow](#):
>
> String, and not the whole tag field?
> 
> I am making sure because [as always] I did not precise enough: there can be many other values in that tag field; and they all must be left alone exactly as they are. I only need to treat x's [and later on other variations of numbers and letters, to which I will modify the descibed / received code]

**What's in the field is a string.** A string is a line of text.

Search google for what these regular expression character classes are for

**^**

 

**$**

Basically, these two char classes anchor the search for the regular expression to either the start **^** or end **$** of the string.

Meaning the string needs to begin with what regular expression follows. 15minutes on youtube would get you understanding how the basics work.  
One vid of thousands on youtube: [https://www.youtube.com/watch?v=DRR9fOXkfRE](https://www.youtube.com/watch?v=DRR9fOXkfRE)

Why not just post full examples of what you want?

For your needs remove the ^

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [August 1, 2017, 5:39am UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/6 "2017-08-01T05:39:42Z")

</div>

> [@Zerow](#):
>
> String, and not the whole tag field?

One textual tagfield contains only one string of characters.

> [@Zerow](#):
>
> ... I am making sure because [as always] I did not precise enough: there can be many other values in that tag field; and they all must be left alone exactly as they are. I only need to treat x's [and later on other variations of numbers and letters, to which I will modify the descibed / received code]

Why don't you distribute the distinguishable data into different tag fields?  
This way each different dataset would be accessible by its own tag-field name.  
And repairing the incorrect data would be easier.

DD.20170801.0939.CEST

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [August 1, 2017, 4:46pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/7 "2017-08-01T16:46:57Z")

</div>

> [@stevehero](#):
>
> [...]  
> the string needs to begin with what regular expression follows  
> [...]

> [@DetlevD](#):
>
> One textual tagfield contains only one string of characters.  
> [...]

So it is impossible to loop on something from the middle, especially when it is unknown where exactly it will be [with it beeing sometimes at the very beginning or at the very end or somewhere in the middle]?

> [@stevehero](#):
>
> [...]  
> Why not just post full examples of what you want?  
> [...]

But I did list some examples

Normally I just put [in this case] \>\>##9X\<\< via the actions, to avoid mistakes

But sometimes I'm just writing [changing, correcting] with a keyboard. I shouldn't do it [to avoid mistakes] but it is easier and quicker sometimes to write just \>\>9x\<\< or \>\>x\<\< [as I already have big clearing action that takes care of such incomplete codes and turns them into \>\>##9X\<\<]. And so I need to not take notice if by mistake there are two x's or three, because of a stuck key or a slip of a finger

> [@DetlevD](#):
>
> [...]  
> Why don't you distribute the distinguishable data into different tag fields?  
> [...]

Because that would end me up with something like a worksheet in Excel, filled with dozens of columns, but most of witch for most of the time would be empty; and still there would have to be one very wide column to house codes with words and not just with two digits [numbers and combinations o a digit and a letter]. I would need to constantly turn on and off such columns or scroll the view horizontally or work on something like two widescreen monitors. And the numbers of errors coming such unclear views would be horrendous

Instead of that I have one column / tag field to house all the codes [my genres in form of codes]

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [August 1, 2017, 5:26pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/8 "2017-08-01T17:26:44Z")

</div>

> [@Zerow](#):
>
> So it is impossible to loop on something from the middle, especially when it is unknown where exactly it will be [with it beeing sometimes at the very beginning or at the very end or somewhere in the middle]?[...]

I just have found a neat solution

I can just simply use "Replace with regular expression"

```
Field: GENRE
Regular expression: 9xx+
Replace matches with: 9XAnd that it is; it works. I have tested it and it does not messed up other values

```

But of course thank you both for your time

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [August 1, 2017, 5:42pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/9 "2017-08-01T17:42:10Z")

</div>

> [@Zerow](#):
>
> Regular expression: 9xx+  
> Replace matches with: 9X

No, no, no.

Use.

9x+

Your example won't replace 9x with 9X like you wanted or maybe I'm missing something again.

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [August 1, 2017, 7:57pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/10 "2017-08-01T19:57:03Z")

</div>

> [@stevehero](#):
>
> No, no, no.
> 
> Use.
> 
> 9x+
> 
> Your example won't replace 9x with 9X like you wanted or maybe I'm missing something again.

You are correct

But change from 9x to 9X is done at some other point with other action; while at this point 9xx serves as a kind of fail safe

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [August 1, 2017, 8:20pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/11 "2017-08-01T20:20:45Z")

</div>

> [@Zerow](#):
>
> You are correct
> 
> But change from 9x to 9X is done at some other point with other action; while at this point 9xx serves as a kind of fail safe

In which case:

\b9x+\b will match only 9xx in these scenarios.

```
wordhere 9xXxXxx wordhere
wordhere.9xxxX wordhere
9xXxX wordhere
word here 9xxXx

```

But NOT these.

```
wordhere9xXxXwordhere
wordhere9xXxX wordhere
wordhere 9xXxXwordhere
word here9xxXx

```

\b in regular expressions searches for word boundaries. I think this is what you're after. I wouldn't know as you've yet to post full examples.

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [August 2, 2017, 5:16pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/12 "2017-08-02T17:16:24Z")

</div>

QUOTE (stevehero @ Aug 2 2017, 00:20) \<{POST\_SNAPBACK}\>

[...]

But NOT these.

```
wordhere9xXxXwordhere
wordhere9xXxX wordhere
wordhere 9xXxXwordhere
word here9xxXx

```

[...]

Point taken

But all values are marked with markers ["##"] and other action takes care of putting / checking them

And such cases like those above I surely would not want to be treated automatically, because they can indicate a big mess [and as such have to be evaluated manually; or automatically by simply wiped out, which is what happens now in my system]

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 9, 2026, 12:26pm UTC](https://community.mp3tag.de/t/how-to-loop-regular-expression/19184/13 "2026-02-09T12:26:55Z")

</div>


