I am trying to find a line inside the contents of a file that I received in a line.
I tried using Pattern and Matcher that worked for this case:
Pattern p = Pattern.compile("(</machine>)"); Matcher m = p.matcher(text); while(m.find()) //if the text "(</machine>)" was found, enter { Counter++; } return Counter;
Then I tried to use the same code to find out how many tags I have:
Pattern tagsP = Pattern.compile("(</"); Matcher tagsM = tagsP.matcher(text); while(tagsM.find()) //if the text "(</" was found, enter { CounterTags++; } return CounterTags;
in this case, the return value is always 0.
source share