Something's strange in the way you have used these regexes, A standard PDB file format does not look so much like the example you have mentioned, the data generated from PDB comes with ATOM or HETATM at the beginning of the line, then the atom position & type, going through again until the end of a line in an atom name again... you seem to have included a lot of brackets for backreferencing in your arrays, that is not really endorsed unless you really strictly have to, why don't you look for another way of reading these lines and putting a condition that enable you to select the lines you want printed and discard those you do not want instead of squeezing your brains this way!!!, however, try to show us an example of a couple of full PDB lines between the code tags, that can make us be able to have better visuals and get closer to understanding what you need to do.