VertexShapeFunction with string pattern matching [duplicate]

I am trying to visualize a heterogeneous graph which nodes are categorical. Here is a dummy graph for implementation:

Input is

graph = UndirectedEdge @@@ {{"u0", "c1"}, {"u1", "c3"}, {"u2", "c0"}, {"u3",
"c2"}, {"u4", "c1"}, {"u0", "i0"}, {"u1", "i0"}, {"u2",
"i0"}, {"u3", "i1"}, {"u4", "i2"}}


And it looks like this by specifying vertex coordinates.

I would like to customize vertex shape by using VertexShapeFunction, but I cannot make the pattern matching work, for instance, I would like to make the nodes starts with m have shape square:

Graph[graph, VertexLabels -> "Name", VertexShapeFunction -> {_?StringStartsQ["u"] -> "Square" }]


I am aware the it should be a pattern, as

CompleteGraph[5, VertexShapeFunction -> {_?EvenQ -> "Star"}, VertexSize -> 0.2]


but I don't know how to make pattern work, I tried:

Cases[{"u1", "p1"}, _?StringStartsQ[#, "u"] &]


Returns empty list.

I know StringCases and Select can easily returns the strings I want, but unfortunately, seems only Cases with pattern matching would work for VertexShapeFunction

The following two works but it's not pattern matching.

StringCases[{"u1", "p1"}, "u" ~~ _]
Select[{"u1", "p1"}, StringStartsQ[#, "u"] &]

• you define graph but then reference eMC. None of the vertices in graph start with m. Commented Apr 9, 2021 at 19:43
• It seems counterintuitive, but you have to use VertexShapeFunction -> {_?(StringStartsQ["m"]) -> "Square" }] Commented Apr 9, 2021 at 19:46
• Thank you for pointing out Jason, I just fixed the inconsistency. Commented Apr 9, 2021 at 19:50
• but VertexShapeFunction -> {_?(StringStartsQ["u"]) -> "Square" }] doesn't work at all. Commented Apr 9, 2021 at 19:54
• this doesn't work for you? What version are you using? Commented Apr 9, 2021 at 20:00