I am studying for the Java OCP certificate. I am taking mock exams to prepare.
Example program:
public class Quetico {
public static void main(String[] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
while (m.find()) {
System.out.println(m.start() + " ");
}
System.out.println("");
}
}
the authors of the OCA/OCP Jave SE 7 Study Guide maintain that the execution:
java Quetico "\B" "^23 *$76 bc"
will produce the output
0 2 4 8
However, when I run the code from Eclipse or test it on an outside source, I get
0 2 4 5 7 10
Am I missing something here, or is it a mistake by the authors of the study guide?
I am adding the actual question from the book below for reference.
"\B"
would be passed as\\B
? – Tales"\B"
is equal to a Java String"\\B"
passed in directly in the code. – Komsomolskmistake by the authors of the study guide
If you run the code and get the same result, it must be considered the claim is in error. Regex engine primitives don't change, in fact\B
means not-word boundary on probably every engine. So, is it possible the claim is in error ? I'd say so.. – Petronilapetronilla