If the second argument of `%substr` is a variable, and it is used in a more complex context then it returns the whole string and not only the relevant part.
e.g. in following sample the gray text should be without customer
@startuml
legend
!$labelWithDetails = "Customer\nPeople that need products"
!$brPos = %strpos($labelWithDetails, "\n")
!$line = %substr($labelWithDetails, 0, $brPos) + " <color:gray>" + %substr($labelWithDetails, $brPos + 2) + "</color>"
$line
endlegend
@enduml
BR Helmut