I'm currently working on a simple parsing program which reads certain patterns out of a file, formats them and then write them into an output file.
The input files look like this
{0,0,0,0,0,0,0,0,0} {1,1,1,1,1,1,1,} {3,3,3,3,3,3,3,3,3,3}
The number of digits vary from block to block and also the digits themselves are basically random. So I'd like to scan the input file for those blocks. This is what I got so far:
Pattern block = Pattern.compile("(\\{.*\\})");
while(scanner.hasNext(block)){
System.out.println(scanner.next(block));
}
But so far, the program doesn't even enter the while
statement. I don't know
if my pattern is wrong or if I'm using the Scanner incorrectly.
And how do I take care of this whitespace between the blocks?
Thanks for your help!
Define the delimiter - the pattern between tokens:
Then to loop simply: