# Using a regular expression in assigning a tag

**URL:** <https://community.mp3tag.de/t/using-a-regular-expression-in-assigning-a-tag/43092>\
**Category:** Support\
**Created:** [September 26, 2018, 2:59am UTC](https://community.mp3tag.de/t/using-a-regular-expression-in-assigning-a-tag/43092 "2018-09-26T02:59:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnanib](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@dnanib](https://community.mp3tag.de/u/dnanib)\
**Post date:** [September 26, 2018, 2:59am UTC](https://community.mp3tag.de/t/using-a-regular-expression-in-assigning-a-tag/43092/1 "2018-09-26T02:59:52Z")

</div>

I want to update the Album field of a large number of files. The albums names are actually the parent directory names, but with a prefix of album release year.

1984 - Some Album

One additional complication is that in years when a band released more than one albums, there are suffixes 'a', 'b' in order on the directory name:

1985a - Album 1  
1985b - Album 2

I want to strip out the year, the suffix if any, and space-dash-space combination and use the remainder to fill the ID3 Album field.

This does not seem to work (Convert \> Tag - Tag):

$regexp(%\_directory%, '^\d{4}[a-z]? - ','')

What am I missing?

---

<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:** [September 26, 2018, 4:31am UTC](https://community.mp3tag.de/t/using-a-regular-expression-in-assigning-a-tag/43092/2 "2018-09-26T04:31:30Z")

</div>

> [@dnanib](#):
>
> `$regexp(%_directory%, '^\d{4}[a-z]? - ','')`

If I see that correctly, then you have a blank behind the comma in front of the apostrophe.  
Strip that and everything should be working:  
`$regexp(%_directory%,'^\d{4}[a-z]? - ','')`

---

<div class="post-metadata">

**Author:** ![dnanib](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@dnanib](https://community.mp3tag.de/u/dnanib)\
**Post date:** [September 26, 2018, 4:45am UTC](https://community.mp3tag.de/t/using-a-regular-expression-in-assigning-a-tag/43092/3 "2018-09-26T04:45:52Z")

</div>

Thanks for the pointer. This is exactly what worked:

$regexp(%\_directory%,'^\d{4}[a-z]? - ',)

---

<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:27pm UTC](https://community.mp3tag.de/t/using-a-regular-expression-in-assigning-a-tag/43092/4 "2026-02-09T12:27:41Z")

</div>


