So I wrote what should be a simple regular expression. But for whatever reason it doesn’t work. .find() always says false.
Edit: The System.out.println("Scanned: "+line); returns the exact lines that are in the file, so it isn’t that the code can’t read it.
public void fetchUndertaleData(){
String name = System.getProperty("user.home");
File file = new File(name+"/appdata/local/UNDERTALE/undertale.ini");
String title = "";
try(Scanner scan = new Scanner(file)){
while(scan.hasNextLine()){
String line = scan.nextLine().trim();
System.out.println("Scanned: "+line);
Matcher extractTitle = Pattern.compile("/^\\[(.*?)\\]$/").matcher(line);
if(extractTitle.find()){
title = extractTitle.group(1)+".";
continue;
}
Matcher extract = Pattern.compile("/([a-zA-Z0-9]+)=\"(.*?)\"/").matcher(line);
if(extract.find()){
String key = title+extract.group(1);
undertale.put(key.toLowerCase(), extract.group(2));
System.out.println("Register: "+key.toLowerCase()+" = "+extract.group(2));
}
}
scan.close();
}catch(Exception e){
System.err.println("Error: "+e.getLocalizedMessage());
}
//Debug
System.out.println(undertale.get("general.love"));
}
File I’m reading from
[quote][Mett]
O=“1.000000”
[Papyrus]
M1=“1.000000”
PS=“1.000000”
[Sans]
M1=“1.000000”
[Flowey]
Met1=“1.000000”
[reset]
reset=“1.000000”
[General]
Gameover=“1.000000”
fun=“9.000000”
Name=“null”
Love=“7.000000”
Time=“318297.000000”
Kills=“10.000000”
Room=“176.000000”
[Toriel]
Bscotch=“1.000000”
TS=“1.000000”
[/quote]