Seperating a line of text

I've got a text file, which I've broken down to read line by line. Each line is in the format of

word1 word 2 [word3] /word4/possible word5/...

So words1, 2, 3 and 4 will definately be there, there might be additional words, but these would be contained within forward slashes, where word three will be contained within square brackets, what sort of approach would I need to break these up?

[411 byte] By [TrapperDavea] at [2007-10-3 11:46:53]
# 1
Regular Expressions will be useful: http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
zadoka at 2007-7-15 14:19:43 > top of Java-index,Desktop,Developing for the Desktop...
# 2

Actually, you don't really need regex. you can use String.split(String str):

public String[] sort(String input)

{

String[] temp = input.split("/"); //All the words

String[] temp2 = temp[0].split(" "); //The first, second, and third words

String[] ret = new String[temp.length + temp2.length]; //The return

ret[0] = temp2[0];

ret[1] = temp2[1];

ret[2] = temp2[2].replaceAll("[", "").replaceAll("]", ""); /*Third word, without brackets*/

for(int i = 0; i < ret.length; i++)

ret[i + 3] = temp[ i ]; //assign the rest of the words

return(ret);

}

I'd think about debugging that piece of code...

Message was edited by:

atoxic

Message was edited by:

atoxic

atoxica at 2007-7-15 14:19:43 > top of Java-index,Desktop,Developing for the Desktop...
# 3
> Actually, you don't really need regex. you can use> String.split(String str):The split method's parameter is a regex. What do you mean you don't need regex?
zadoka at 2007-7-15 14:19:43 > top of Java-index,Desktop,Developing for the Desktop...
# 4

I mean without making instances of regex. Sorry, I wasn't clear on that.

Alternatively, I thought up of an easier way

public String[] sort(String input){return(input.replace("[","").replace("/"," ").replace("] ","").split(" "));}

The spaces DO matter, so double-check on that.

atoxica at 2007-7-15 14:19:43 > top of Java-index,Desktop,Developing for the Desktop...