I am using the following Javascript to read strings out of a text file and process them with a regular expression
while (!textFile.AtEndOfStream)
{
currLine = textFile.ReadLine();
match = re.exec(currLine);
do stuff with match
}
The problem I have is that every other time re.exec is called it fails and returns null; so the first row is processed correctly, but the second row results in null, then the third row works, and the fourth row results in null.
I can use the following code to get the result I want
while (!textFile.AtEndOfStream)
{
currLine = textFile.ReadLine();
match = re.exec(currLine);
if (match == null) match = re.exec(currLine);
}
but that seems a bit of a nasty kludge. Can anyone tell my why this happens and what I can do to fix it properly?