How to format a bash variable to a Docker Compose project name?

If I have the following file structure:

./test/docker-compose.yml

and I run docker-compose up. The name of the container is formatted like: test_service_1.

But if I have this folder:

./TeST__-O0%Ri3e/docker-compose.yml

and I run docker-compose up. The name of the container is formatted like: test__-o0ri3e_service_1.

Question

I store the name of the Docker container I need in a bash variable like this: ${PWD##*/}_service_1.

How can I format ${PWD##*/} so that it reflects the same format Docker Compose uses?

Source: StackOverflow