in reply to regex incorrectly matching newline
Show us the loop. Your sample code matches if any character in $i is within the set. Unless you are iterating over the string one character at a time you are seeing expected behaviour.