"Law" originally referred to legislative statute, but in the idiom may refer to any kind of rule.Intentionally following the letter of the law but not the spirit may be accomplished through exploiting technicalities, loopholes, and ambiguous language.