in reply to Re^4: need help with a regex
in thread need help with a regex

The logic was naively copied from the OP. To say it was buggy does not surprise me, though I probably should have tried to divine intent and test appropriately.