this is really impenetrable.  

what is in expandedPlaceholders[i] and why would you slice it starting at 2 if pIndex[0] == pIndex[2]?