Your problem is that when you scan the file line by line, you may match the keyword, but it can be part of a comment? For example
/*
keyword
*/
?
In this case you can just set a variable to True if you encounter a comment, and set it back to False if you find the end of the comment. If you find the keyword while the variable is False, you know that the keyword appears in the code. In a similar way you can check if // appears in the same line.
'//' in currentLine