in reply to Edit a New file in place after reading it in

In addition to the guidance provided by other commenters above, you should note that the data sample you provided has much trailing whitespace. You may have accidentally entered that whitespace when creating your original post -- but it also be present in the real-world data you are analyzing.

After chomping a given line of input, you should trim off the trailing whitespace before applying any regex pattern to the line. That way, Xi Wong        $ will be reduced to Xi Wong$ and will be better detected during pattern matching.

Jim Keenan