lpeg = require "lpeg" local P, S, R, B = lpeg.P, lpeg.S, lpeg.R, lpeg.B -- lpeg functions Artist, Title, Album = "", "", "" -- return values function CARTIST(s) Artist = s end -- capture Artist function CTITLE(s) Title = s end -- capture Title function CALBUM(s) Album = s end -- capture Abum -- LPEG Pattern -- global lpeg pattern DELIMITER = P" - " -- space minus space DELIMITER2 = P" / " -- space slash space ALL = P(1) FALLBACK = ((ALL - DELIMITER)^1 / CARTIST) * DELIMITER * -- Artist (((ALL - DELIMITER2)^1 / CALBUM) * DELIMITER2)^-1 * -- Album (ALL / CTITLE) -- Titel -- stream spezific lpeg pattern PREJUNK = P"Sie hören jetzt: " + P"we are playing now: " POSTJUNK = DELIMITER + DELIMITER2 + P"'" * R"09"^1 + P"[" * (1 - P"]")^0 * P"]" PATTERN = PREJUNK^0 * ((ALL - DELIMITER)^1 / CARTIST) * DELIMITER * (((ALL - DELIMITER2)^1 / CALBUM) * DELIMITER2)^-1 * ((ALL - POSTJUNK)^1 / CTITLE) -- end stream spezific lpeg pattern -- program body -- line = io.read("*l") if PATTERN:match(line) or FALLBACK:match(line) then io.write("Artist: ".. Artist .. "\n") io.write("Title : ".. Title .. "\n") io.write("Album : ".. Album .."\n") else print("no match.") end