Route to a specific microservice based on entity on path

I have a specific requirements in my project, all request with a specific set of entities

/servicex/xxx/entity1
/servicex/yyy/entity1
/servicex/zzz/entity1

/servicex/xxx/entity2
/servicex/yyy/entity2
/servicex/zzz/entity2

should be directed to microservice1 that manages entity1 and entity2, while

/servicex/xxx/entity5
/servicex/yyy/entity5
/servicex/zzz/entity5

/servicex/xxx/entity6
/servicex/yyy/entity6
/servicex/zzz/entity6

should be directed to microservice2 that manages entity5 and entity6

Is there any Kong feature that enables this kind of configuration or in alternative what is the preferred way to extend Kong to implement this behaviour?