Q:

Reading just integers from an input stream of integers and other characters

First question on here, so, sorry if it's not a very good one.
I'm working on a java program that will take in input like this

(1>2)(2>3)(3>4)(4>5)
(6>7)(7>8)(6>8)

and then store the numbers in an array. Right now, I'm just trying to get the parsing right. So I'm just printing the output on separate lines. Here's what I've been trying:
Scanner input = new Scanner(System.in).useDelimiter("\\W");
for(int i = 0; (line = input.next()) != null; i++){
    System.out.println(i + ": " + line);
}

and that's been getting this output

0: 1
1: 2
2: 
3: 2
4: 3
5: 
6: 3
7: 4
8: 
9: 4
10: 5
11: 
12: 
13: 6
14: 7
15: 
16: 7
17: 8
18: 
19: 6
20: 8
21: 

It looks like when two delimiters are next to each other such as ')(', it prints out whitespace. I'm not sure why it's doing this or if it can even be fixed. Is there a way to use both characters of ')(' as one delimiter? Is there anyway to get rid of the whitespace when calling input.next() without using input.next() as a continue on the whitespace? Or is there something better than Scanner that will avoid this problem? I looked into BufferedReader and InputStreamReader, but neither seem useful for this situation. 
Thanks for any input and your time. :)

A:

It looks like when two delimiters are next to each other such as ")(", it prints out whitespace. 

Your delimiter \\W is set to look for one non-word character so if there are two delimiters next to each other it means that there is empty string between them and this empty string is returned.  
If you want delimiter to match one or more non word characters you need to use + quantifer like \\W+.

