Java Scanner with regex delimiter
问题 Why does the following code return false? Scanner sc = new Scanner("-v "); sc.useDelimiter("-[a-zA-Z]\\s+"); System.out.println(sc.hasNext()); The weird thing is -[a-zA-Z]//s+ will return true. I also can't understand why this returns true: Scanner sc = new Scanner(" -v"); sc.useDelimiter("-[a-zA-Z]\\s+"); System.out.println(sc.hasNext()); 回答1: A scanner is used to break up a string into tokens. Delimiters are the separators between tokens. The delimiters are what aren't matched by the