I would like to be able to parse strings like the following: "123456abcd9876az45678". BNF is as follows:
number: ? definition of an int ?
word: letter { , letter }
expression: number { , word , number }
However, the java.util.scanner class does not allow me to do the following:
Scanner s = new Scanner("-123456abcd9876az45678");
System.out.println(s.nextInt());
while (s.hasNext("[a-z]+")) {
System.out.println(s.next("[a-z]+"));
System.out.println(s.nextInt());
}
Ideally, this should give:
-123456
abcd
987
az
45678
I really hoped that java.util.Scanner would help me, but it looks like I will need to create my own scanner. Is there anything that is already present in the Java API to help me?
The question is missing too much information. And so all the answers are valid for the question, but not for my problem.
source
share