# Expression to delete defined strings from tag

**URL:** https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409
**Category:** Support
**Created:** [January 17, 2014, 4:18am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409 "2014-01-17T04:18:42Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![lolspops](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@lolspops](https://community.mp3tag.de/u/lolspops)
#### Post date: [January 17, 2014, 4:18am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/1 "2014-01-17T04:18:42Z")

</div>

Hello,

I am trying to delete certain strings from my tag using expressions. First, I have tracks that are like "03/10" or "01/07" and I just want it to be "3/10" and "1/7". However, if I search specifically for "0" to replace as nothing, things like "03/10" will be "3/1" which would not work. Is there a better way say, to only delete leading zeroes?

Secondly, I have Album titles as _xxx_ [_xxx_] but I want to delete everything in and including the square brackets.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [January 17, 2014, 5:17am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/2 "2014-01-17T05:17:32Z")

</div>

At least 2 solutions:  
1: use the numbering wizard and renumber your files.  
2: Create an action of the type "Replace with regular expression" for TRACK  
Enter as search string: ^0  
Leave format string empty.

Second case, same type of action. Only this time other field and enter as search string:  
' ['.\*']'  
again: leave the search string empty

---

<div class="post-metadata">

### Author: ![lolspops](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@lolspops](https://community.mp3tag.de/u/lolspops)
#### Post date: [January 17, 2014, 7:49am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/3 "2014-01-17T07:49:37Z")

</div>

> [@ohrenkino](#):
>
> At least 2 solutions:  
> 1: use the numbering wizard and renumber your files.  
> 2: Create an action of the type "Replace with regular expression" for TRACK  
> Enter as search string: ^0  
> Leave format string empty.
> 
> Second case, same type of action. Only this time other field and enter as search string:  
> ' ['.\*']'  
> again: leave the search string empty

Thank you, but is it possible for the second solution to modify the total tracks too because only the current track works eg. 1/07. Also, the search string input for the square brackets one don't work.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [January 17, 2014, 9:52am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/4 "2014-01-17T09:52:15Z")

</div>

> [@lolspops](#):
>
> Thank you, but is it possible for the second solution to modify the total tracks too because only the current track works eg. 1/07. Also, the search string input for the square brackets one don't work.

Try  
' [.\*]'  
(fewer apostrophes, added )

For the track number stuff:  
add an action of the type simple "Replace" to the already created action (Select the action group, klick Edit, klick New)  
enter as search string:  
/0  
enter as replace string:  
/

---

<div class="post-metadata">

### Author: ![lolspops](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@lolspops](https://community.mp3tag.de/u/lolspops)
#### Post date: [January 17, 2014, 10:02am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/5 "2014-01-17T10:02:34Z")

</div>

> [@ohrenkino](#):
>
> Try  
> ' [.\*]'  
> (fewer apostrophes, added )

Still does not work

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 17, 2014, 12:29pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/6 "2014-01-17T12:29:57Z")

</div>

Patterns to remove leading zeros from the track field are:

Multiple

```
$regexp(%track%,^0+,$1)

```

single

```
$regexp(%track%,^0,$1)

```

Though removing leading zeros will 'break' sorting in Windows Explorer and media player applications, so fracks will become ordered as

1  
10  
11  
.  
.  
19  
2  
20  
21  
...

and so on.

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 17, 2014, 1:08pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/7 "2014-01-17T13:08:17Z")

</div>

to remove the leading zero after the '/' will need an action group creating with running this replace first

```
$replace(%track%,/0,/)

```

then the regexp in the post above.

Never tried in MP3Tag but I don't think nested regular expressions are going to be possible.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [January 17, 2014, 5:47pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/8 "2014-01-17T17:47:47Z")

</div>

> [@lolspops](#):
>
> Still does not work

Sorry, i was puzzled and made it far too complicated.  
[.\*]  
will do it

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 17, 2014, 6:49pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/9 "2014-01-17T18:49:00Z")

</div>

> [@ohrenkino](#):
>
> Sorry, i was puzzled and made it far too complicated.  
> [.\*]  
> will do it

?????

That would just leave \ in the track field

A regex match pattern of .\* means "match any character (except newline [ASCII 13] ) 1 or more times"

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [January 17, 2014, 7:20pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/10 "2014-01-17T19:20:16Z")

</div>

> [@Chris Hirst](#):
>
> ?????

You are probably right - I was refering to the second problem with the square brackets part and not the track number problem.

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 17, 2014, 8:46pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/12 "2014-01-17T20:46:33Z")

</div>

> [@ohrenkino](#):
>
> I was refering to the second problem with the square brackets part and not the track number problem.

Doesn't a regexp to empty a field though

You can  
Ctrl+A (select all)  
select in the tag panel then Ctrl+S to save

Or for scripting/Convert (Alt+5)

Set the field and an action of $replace(%field%,)

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [January 17, 2014, 8:56pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/13 "2014-01-17T20:56:22Z")

</div>

> [@Chris Hirst](#):
>
> Doesn't a regexp to empty a field though
> 
> You can  
> Ctrl+A (select all)  
> select in the tag panel then Ctrl+S to save
> 
> Or for scripting/Convert (Alt+5)
> 
> Set the field and an action of $replace(%field%,)

Are you discussing this theoretically or have you tried it?  
The op's request was to delete a text in square brackets, but leave the rest.  
And this is exactly what the [.\*] will do.  
It will take that part of the string that has a square bracket at the beginning, something in between and a square bracket at the end and replace it with nothing. The rest of the field will remain unaltered.

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 17, 2014, 9:26pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/15 "2014-01-17T21:26:26Z")

</div>

> [@ohrenkino](#):
>
> Are you discussing this theoretically or have you tried it?  
> The op's request was to delete a text in square brackets, but leave the rest.  
> And this is exactly what the [.\*] will do.  
> It will take that part of the string that has a square bracket at the beginning, something in between and a square bracket at the end and replace it with nothing. The rest of the field will remain unaltered.

Apologies I had misread the post.

---

<div class="post-metadata">

### Author: ![lolspops](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@lolspops](https://community.mp3tag.de/u/lolspops)
#### Post date: [January 17, 2014, 11:07pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/16 "2014-01-17T23:07:03Z")

</div>

Thank you all for the help. One final request:  
I have fields with repeated strings eg. 'DATE' = '2014-01-17 2014-01-17 2014-01-17' and looking through my tagging script it seems this is creating the duplicate strings:

> [@](#):
>
> regexpreplace "(releaseDate":")(\d\d\d\d)-(\d\d)-(\d\d)" "$1$2-$3-$4"
> 
> ```
> outputto "RELEASE DATE"
> sayregexp "(?<=releaseDate\":\")[^\"]+"
> 
> ```

Is there a way I can fix this or an action group to fix it afterwards?

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 18, 2014, 12:13am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/17 "2014-01-18T00:13:53Z")

</div>

Regular expressions are 'greedy' by nature, meaning they will match as much as possible,

If you add a ? after the repeat, it makes the match 'non-greedy' so it matches the shortest possible string

and instead of \d\d\d\d use a repeating set, so a 'non-greedy four digit pattern is;

```
\d{4}?
```

---

<div class="post-metadata">

### Author: ![lolspops](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@lolspops](https://community.mp3tag.de/u/lolspops)
#### Post date: [January 18, 2014, 1:35am UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/18 "2014-01-18T01:35:47Z")

</div>

Thank you, it works perfectly

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [January 18, 2014, 4:30pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/19 "2014-01-18T16:30:59Z")

</div>

\d{4}? The question mark there makes no sense to me, what's the difference from \d{4}

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 18, 2014, 6:41pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/20 "2014-01-18T18:41:08Z")

</div>

The ? makes the match "non-greedy"

\d{4} would match any and all four digit sequences in the same string, adding the ? AFTER the repeat means it will only match the shortest possible sequence.

so $regexp(' 1234 1234 1234',\d{4} $1) will return the entire string without the spaces ie; '123412341234' (greedy), whereas $regexp(' 1234 1234 1234',\d{4}?, $1) will only return the first sequence of '1234' which is the shortest possible match from that string, so is a 'non-greedy' or a 'lazy' match.

More on "laziness' vs 'greediness' in Regular Expressions

[http://www.regular-expressions.info/repeat.html](http://www.regular-expressions.info/repeat.html)

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [January 22, 2014, 6:59pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/21 "2014-01-22T18:59:34Z")

</div>

I thought about it and my take is that your explanation is not correct.

The ? on \d{4}? has no effect. {4} if a fixed repetition.  
It only works with i.e. \d{4,6}? or \d{4,}?

You're mixing up greediness with global matching which means how often a complete pattern is matched in a string (either just one time or as often as possible). This is activated in Mp3tag (match as often as possible) and cannot be changed afaik.  
Example:  
$regexp(aaa,a{1},) =\> empty  
$regexp(aaa,a{1}?,) =\> empty

If global matching was off (match only one time) the result would be _aa_

---

<div class="post-metadata">

### Author: ![chrishirst](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@chrishirst](https://community.mp3tag.de/u/chrishirst)
#### Post date: [January 22, 2014, 9:52pm UTC](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409/22 "2014-01-22T21:52:35Z")

</div>

> [@](#):
>
> I thought about it and my take is that your explanation is not correct.

In that case.  
The MP3Tag help needs rewriting

> [@](#):
>
> Repeats
> 
> - repeated any number of times including zero
> 
> - repeated any number of times, but at least once  
> ? repeated zero or one times only  
> a{n} is the letter "a" repeated exactly n times  
> a{n,} represents the letter "a" repeated at least n times with no upper limit  
> a{n,m} represents the letter "a" repeated between n and m times  
> Non-greedy repeats
> 
> Non-greedy repeats are possible by appending a '?' after the repeat; a non-greedy repeat is one which will match the shortest possible string.

The document at regular-expression.info linked in earlier post.

The technical spec for a Perl regex

> [@](#):
>
> \*? Match 0 or more times, not greedily
> 
> ```
> +? Match 1 or more times, not greedily
> ?? Match 0 or 1 time, not greedily
> {n}? Match exactly n times, not greedily (redundant)
> {n,}? Match at least n times, not greedily
> {n,m}? Match at least n but not more than m times, not greedily
> 
> ```

AND The POSIX specifications for the 'Boost' regex library.  
[http://www.boost.org/doc/libs/1\_55\_0/libs/...ic\_syntax.emacs](http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/basic_syntax.html#boost_regex.syntax.basic_syntax.emacs)

..... .....

But I'll take your word for the appended '?' not setting a non-greedy repeat when following a group or an atomic repeat.

[Next page](https://community.mp3tag.de/t/expression-to-delete-defined-strings-from-tag/15409.md?page=2)
