I am trying to filter some information out of a .txt file.
The file should be read, and I want to put all strings matching 'AT.*.1' in an ArrayList.
Example of the txt file:
Test text AT5X00.1 WednesdayAT5.1 January 26thAT9H99.1 AT6P6.1
And then I want an ArrayList like this:
[AT5X00.1, AT5.1, AT9H99.1, AT6P6.1]
I am not very experienced in programming, so maybe it's very easy but I'm stuck. This is what I tried so far:
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
String filename = file.getAbsolutePath();
textfield1.setText(filename);
String arr = new String();
try {
Scanner input = new Scanner (file);
while (input.hasNext()) {
textarea1.setText(input.nextLine());
//input.close();
}
} catch (FileNotFoundException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
String content = textarea1.getText();
ArrayList<String> myList = new ArrayList<String>Arrays.asList(content.split("AT")));
This doesn't work because it only uses the last line instead of the whole file, and I tried to split it with "AT" instead of with a RE, but this doesn't work because the AT is removed then. And I also have "AT" strings in the file not ending with .1, and I don't want that strings in my list. So, I should use a RE, I think.
Sorry if my grammer is not the best, but English is not my native language. I hope anyone can help me out. Thanks :)
String pat = "\\bAT\\S*\\.1\\b";(\Smatches a non-whitespace char).