SSP SSP - 1 month ago 8
Java Question

Java Matcher class with regex and loop

String sCurrentLine;
br = new BufferedReader(new FileReader(path));

while ((sCurrentLine = br.readLine()) != null) {

Pattern pattern = Pattern.compile(".*?unregistKey\\(tvKey\\.(.*?)\\);");
Matcher m= pattern.matcher(sCurrentLine);
if(m.matches()) {
String abc = m.group(1) ;
System.out.println ("aaaaaaaaaaaaaa" + abc.toString());
}
}


Why this code is looping more than 1 time.
I checked this call to this code but its coming only 1 time.

o/p is N times like this:

aaaaaaaaaaaaaaKEY_1
aaaaaaaaaaaaaaKEY_2
aaaaaaaaaaaaaaKEY_3
aaaaaaaaaaaaaaKEY_CH_UP
aaaaaaaaaaaaaaKEY_PANEL_CH_UP
aaaaaaaaaaaaaaKEY_CH_DOWN
aaaaaaaaaaaaaaKEY_1
aaaaaaaaaaaaaaKEY_2
aaaaaaaaaaaaaaKEY_3
aaaaaaaaaaaaaaKEY_CH_UP
aaaaaaaaaaaaaaKEY_PANEL_CH_UP
aaaaaaaaaaaaaaKEY_CH_DOWN

Answer

You will see this output only when the input file contains the same pattern several times (i.e. there are several lines that contain KEY_1, etc).

Comments