He instalado Apache Netbeans y cuando ejecuto el programa en el que me debe pedir una entrada de teclado indicado por el método printf() resulta que debo insertar primero la entrada de teclado y después me pide la entrada de teclado del método printf. Para ello adjunto un codigo y su resultado: public class RegexTextHarness_01 {
public class RegexTextHarness_01 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.printf("%nEnter your regex: ");
Pattern pattern = Pattern.compile(in.nextLine());
System.out.printf("%nEnter input string to search: ");
Matcher matcher = pattern.matcher(in.nextLine());
boolean found = false;
while (matcher.find()) {
System.out.printf("I found the text" +
" \"%s\" starting at " +
"index %d and ending at index %d.%n",
matcher.group(),matcher.start(),matcher.end());
found = true;
}
if(!found){
System.out.printf("No match found.%n");
}
in.close();
}
}
}
Resultado: --- exec-maven-plugin:3.0.0:exec (default-cli) @ mavenproject4 ---
DOG DOGF Enter your regex: Enter input string to search: I found the text "DOG" starting at index 0 and ending at index 3.
--- exec-maven-plugin:3.0.0:exec (default-cli) @ mavenproject4 ---
DOG
DOGF
Enter your regex: Enter input string to search: I found the text "DOG" starting at index 0 and ending at index 3.