Search code examples
stringlualua-patterns

Lua detect a character/string repeated in all text


I have several documents on a folder. Some of them, has this kind of text:

text="???????????????????????????????????? ??????????????????????? ?????????????????????????????????? ????????????? ???????????????????? ?????? ? ? ???? ????????????? ??????????? ????????????????????? ?????? ? ? ???? ????????? ?????????????????? ??????????????????????? ??????????? ????? ??????? ?????????????? ??????????????????????? ?????? ? ? "

I would like to recognize these documents and put this variable text like: text="".

My problem is, how could I recognize this pattern? as you see, there are several "?" repeated with no identical number of repeats. The pattern should be "if there is no text and only "?" characters, delete content.


Solution

  • Use the pattern "[?%s]*", which means zero or more of ? or whitespace characters.

    if text:gsub("[?%s]*", "") == "" then
      -- do something
    end