I have a polygon layer that has lines showing rivers. A river with the same name attribute might be consisted of a few lines touching each other. For example, in the image below, the river consists of 4 separate lines (with the same name in the name attribute column). The small line shown in red belongs to another river with a different name.
I need to merge the lines with the same names together and I know ways such as merge, join by attribute etc, however I cannot simply use merging by same name because it can happen that a line belonging to the same river (thus having the same name attribute) does not intersect with the rest of the river and cannot be merged into other lines. Is there a way in QGIS 3.22.5 to unite the lines belonging to same river together (having same name attribute), but only those ones which touch in one point?