Regexes, to me, are a different language entirely, but I think I have the hang of it now. I'm writing a macro to convert a Word doc saved as .txt to a certain format which I can make more use of. I'm merely reading the file, concatenating it into one humongous string with newlines intact, and doing the following with this array:
Entries 1 and 2 are the find/replace regexes, respectively.
Entry 3 determines whether to run the replaceFirst(1,2) or replaceAll(1,2) method. This saved time originally, but now the two marked with * are taking up to 40 seconds to run, compared with <10 ms for the others.
String[][] regexes = { {"\t+","","a"}, {"<.*?>\n*","\n","a"}, {"(?i)half ?time","","a"}, {"\n([0-9]{1,2}|(TIE|TB))(\\.|\\))? *","","a"}, {"(?i)(.*\n)+\n*.*toss-?ups\n*","","f"}, // * {"(\n *)+","\n","a"}, {"(?i)((.+\n?ANSWER:.+\n)*)(.*\n)+.*bon(uses|i)\n","$1‡ß","f"}, // * }; // more stuff
I originally thought the drastically lengthened search time was because it was looking through the rest of the files, which aren't large at all, but replaceFirst() fires normally, so it's a problem with the actual expression. How do I fix this so that it runs in a time comparable to the others?