How to do a conditionnal sum based on a string in an array?

Here is the playground, sorry for the single line in the first post.

To be clear: I want to know the size of all entries in a directory, and I want to be able to do it either with exact string matching or with a “like” operator (/bi*/).
So for instance, if I want to get this information for all entries is /bidule/1, it should give me 100.
If I match it for /bidule*, /bid* or just /*, it should give me 133.

I want to know how to do this so I can apply it to other string criteria, like the name or other attributes I have.