# Counting the occurrence of a character in a string

**URL:** https://community.mp3tag.de/t/counting-the-occurrence-of-a-character-in-a-string/13257
**Category:** Export
**Created:** [March 26, 2012, 9:09am UTC](https://community.mp3tag.de/t/counting-the-occurrence-of-a-character-in-a-string/13257 "2012-03-26T09:09:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dario](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dario](https://community.mp3tag.de/u/dario)
#### Post date: [March 26, 2012, 9:09am UTC](https://community.mp3tag.de/t/counting-the-occurrence-of-a-character-in-a-string/13257/1 "2012-03-26T09:09:31Z")

</div>

Hi everyone!  
I hope I'm writing in the right section. I also searched a bit on the forum and I couldn't find any topic on this subject...

I have a string with artist names separated by commas, and I need to know how many artist are in that string.  
Is it possible, for example, to know how many times regexp replaced something?

Any other way I?

Thanks a lot,  
Dario

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [March 26, 2012, 10:30am UTC](https://community.mp3tag.de/t/counting-the-occurrence-of-a-character-in-a-string/13257/2 "2012-03-26T10:30:38Z")

</div>

This should give you the number of artists:  
$add($len($regexp(%artist%,'[^,]',)),1)

no comma = one artist  
one comma = two artists  
two commas = three artists  
....

---

<div class="post-metadata">

### Author: ![dario](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dario](https://community.mp3tag.de/u/dario)
#### Post date: [March 26, 2012, 11:11am UTC](https://community.mp3tag.de/t/counting-the-occurrence-of-a-character-in-a-string/13257/3 "2012-03-26T11:11:39Z")

</div>

Thank you very much! This is a very interesting solution 🙂

---

<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 2, 2015, 7:03am UTC](https://community.mp3tag.de/t/counting-the-occurrence-of-a-character-in-a-string/13257/4 "2015-07-02T07:03:35Z")

</div>

> [@dario](#):
>
> Thank you very much! This is a very interesting solution 🙂

The following proposal could also be of interest.

**$len($regexp([%ARTIST%','],'[^,]',))**

no artist --\> 0  
no comma --\> one artist --\> 1  
one comma --\> two artists --\> 2  
two commas --\> three artists--\> 3

DD.20150702.1103.CEST
