How can galaxies collide in an expanding universe?
Galaxies tend to group together and be gravitationally bound.
Galaxies tend to clump together into groups or clusters. A group can consist of a small number of galaxies which are gravitationally bound to each other. Clusters are bigger groupings which can contain thousands of galaxies and can contain groups of galaxies.
Our Milky Way galaxy and the Andromeda galaxy are the largest of our local group of over fifty galaxies. They are all gravitationally bound together. The Milky Way and Andromeda galaxies will collide in about four billion years time.
Although the Universe is expanding, gravity is strong enough to keep groups and clusters of galaxies together. Galaxies in groups and clusters can be pulled together by gravity and collide.