Add label with regexp from container name in promtail

I have a some of docker containers with names:

  • project1-api
  • project1-crons
  • project2-api
  • project2-crons
    And I need to have a label like “project1”, “project2” to filter in in Grafana Loki
    So I think to parse log in promtail with some regexp to add label “project1”, “project2” etc, but cann’t to have a correct config of Promtail
    Maybe there are other way to solve my problem, so you are welcome…

Thanks for understanding