I am trying to read the specified file format with Scanner and Pattern input, for example:
Pattern p = Pattern.compile("\\d+\\sx\\s\\d+"); Scanner sc = new Scanner(System.in); String input = ""; try { input = sc.next(p); } catch(NoSuchElementException ne) { System.out.println("No such token"); } sc.close(); System.out.println(input);
But when I use 1 x 1 for input, it throws NoSuchElementException
When using the \\d+x\\d+ template and 1x1 input, it works, but not with spaces in the template, am I doing something wrong?
source share