file = "./Light Novels/Isekai/Tsuki ga Michibiku Isekai Douchuu, Chapter 0_ Prologue - Chapter 199 (66)/Tsuki ga Michibiku Isekai Douchuu, Chapter - Azumi Kei.txt" local H = io.open(file) local S = H:read"a" H:close() print"READ FILE" local start, lastword, fin = S:match"()(%w+)()%W+$" print(lastword) fin = fin-1 local bench = require'bucket.misc.benchmark' local function straightmatch() return S:match"(%w+)%W+$" end local function subfirst() return S:sub(start,fin) end local function reverse() S:reverse() end -- just reverse local function reverseit() return S:reverse():match"%w+":reverse() end io.write"reverseit: " bench.Benchmark_once_portable(true, reverseit) io.write"reverse(): " bench.Benchmark_once_portable(true, reverse) io.write"straightmatch: " bench.Benchmark_once_portable(true, straightmatch) io.write"subfirst: " bench.Benchmark_once_portable(true, subfirst) --[[ Results: reverseit: Clock: 0.017444 straightmatch: Clock: 1.390177 subfirst: Clock: 2.9999999999752e-06 3.05user 0.03system 0:03.09elapsed 99%CPU (0avgtext+0avgdata 25160maxresident)k 0inputs+0outputs (0major+7584minor)pagefaults 0swaps So sub is the slowest! idk why straightmatch is fast, but that's because its a good pattern a bad pattern though? looped for a long time (almost a minute) So reversing is great, but I imagine utf8 would really mess it up --]]