I'm merely quoting from the story. Furthermore, we don't know exactly when Holmes (allegedly) discovered Moriarty's identity. Here's how Holmes describes it, in The Final Problem
For years past I have continually been conscious of some power behind the malefactor, some deep organising power which forever stands in the way of the law, and throws it shield over the wrong-doer. Again and again in cases of the most varying sorts—forgery cases, robberies, murders—I have felt the presence of this force, and I have deduced its action in many of those undiscovered crimes in which I have not been personally consulted. For years I have endeavoured to break through the veil which shrouded it, and at last the time came when I seized my thread and followed it, until it led me, after a thousand cunning windings, to ex-Professor Moriarty of mathematical celebrity. [my emphasis]
Thanks
Vijay