I have been reading a lot of questions and answers about using delimiters and patterns but still having a lot of trouble figuring this one out.I want to read a text file that may or may not be jumbled up and pick the words out of it. So with input such as this
"the.dog,jumped over the hole@bob's house"
This would give me the following words
[the, dog, jumped, over, the, hole, bob's, house]
I would then do something with each word.
Scanner s1 = new Scanner(fileName);
temp = s1.next(String pattern = "no clue");
//do something with temp
I feel like a pattern would be the best way to do it but how would I make a pattern that includes any variation chars long as it starts with a letter and ends when it reaches any of these characters? `. , * % " ( ) & $ ? < > ! - : ; @ #` or any type of `white space`.
I know I could do it a very ugly way with very crappy run time efficiency. Any help will be greatly appreciated or direction to another question that maybe of help that I haven't found. I would suggest you to follow the approach as suggested below by other users. In addition, try to read this regex pattern from some external text file. This would allow you to experiment with the program easily (w/o compiling).
以上就是What is the best way to break up a text file in java given certain limitations on what a valid string is?的详细内容，更多请关注web前端其它相关文章！