Hej, mam do rozkminienia zadanie programistyczne, w którym muszę wyszukać poprawne instrukcje warunkowe if. Instrukcje, które są zakomentowane, bądź między cudzyuszami nie wchodzą w grę. Na razie rozkminiłem taki kod:
public int getIfCount() {
String line;
int counter = 0;
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(this.path));
Pattern compiledPattern = Pattern.compile("if*(.*)", Pattern.CASE_INSENSITIVE);
while ((line = bufferedReader.readLine()) != null) {
Matcher m = compiledPattern.matcher(line);
while (m.find()) {
counter++;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return counter;
}
Nie podoba mi się ta gwiazdka po ifie. Próbowałem coś takiego, ale "if\s*(.*)", ale nie zlicza poprawnie.
Druga sprawa. Jak wykluczyć komentarze i ify wrzucone między " "?
PanamaJoep_agonPanamaJoePerlMonkp_agon