This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Your line 6 splits the input string into tokens based on a delimiter "any number of spaces (including 0), followed by fish, followed by any number of spaces".
This will split your string as follows: "1/ fish /2/ fish /red/ fish /blue/ fish", which gives you the tokens: "1", "2", "red", "blue".
The commented out line 7 is very similar, but because the delimiter doesn't include spaces, it splits the string as: "1 /fish/ 2 /fish/ red /fish/ blue /fish", which gives you the tokens: "1 ", " 2 ", " red ", " blue ". Note the spaces.
That would work. But then on line 9 you are trying to read the next token as an int. "1" converts to an int with no difficulties. But " 1 " doesn't, so it'll throw an exception using the second delimiter.
@Sandra: Your delimiter is " fish ". Notice the space in the end. Now in the sample string the last fish doesn't have a space in the end.
So, this does not match the delimiter. Thats why it prints "blue fish".
Whereas, if the delimiter is "\\s*fish\\s*" then it will match zero or more space in the end.