in reply to reading from a text file

Also remember that the dot has the special meaning of "any character" in a regex, so while your code is working ( with robartes' correction ) it's not exactly doing what you think .

Since you want to match real dots you should probably use \. in your expressions ( escaping the . metacharacter with \ will make it lose its special meaning)